Skip to content

Commit

Permalink
Using withMethod to update request object based on _method
Browse files Browse the repository at this point in the history
  • Loading branch information
cjquinn committed Oct 10, 2016
1 parent 8793b83 commit a16aa45
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Routing/Middleware/RoutingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
Router::setRequestContext($request);
$params = (array)$request->getAttribute('params', []);
if (empty($params['controller'])) {
$path = $request->getUri()->getPath();
$parsedBody = $request->getParsedBody();
$method = is_array($parsedBody) && isset($parsedBody['_method']) ? $parsedBody['_method'] : $request->getMethod();
$request = $request->withAttribute('params', Router::parse($path, $method));
if (is_array($parsedBody) && isset($parsedBody['_method'])) {
$request = $request->withMethod($parsedBody['_method']);
}
$request = $request->withAttribute(
'params',
Router::parse(
$request->getUri()->getPath(),
$request->getMethod()
)
);
}
} catch (RedirectException $e) {
return new RedirectResponse(
Expand Down

0 comments on commit a16aa45

Please sign in to comment.