Skip to content
Permalink
Browse files

Using withMethod to update request object based on _method

  • Loading branch information...
cjquinn committed Oct 7, 2016
1 parent 8793b83 commit a16aa45a053b14ff37b4ba99b67ad406284be50e
Showing with 10 additions and 3 deletions.
  1. +10 −3 src/Routing/Middleware/RoutingMiddleware.php
@@ -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(

0 comments on commit a16aa45

Please sign in to comment.
You can’t perform that action at this time.