-
Notifications
You must be signed in to change notification settings - Fork 90
Add route match params to request attributes #210
Add route match params to request attributes #210
Conversation
9abe66e
to
79fe956
Compare
Looks good to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think would be also nice inject whole RouteMatch, not only individual matched params (as we have it in expressive).
@@ -59,7 +59,11 @@ public function onDispatch(MvcEvent $event) | |||
|
|||
$caughtException = null; | |||
try { | |||
$return = $middleware(Psr7Request::fromZend($request), Psr7Response::fromZend($response)); | |||
$psr7Request = Psr7Request::fromZend($request); | |||
foreach ($routeMatch->getParams() as $key => $value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think will be nice to inject also while RouteMatch
(as we have it in expressive: https://github.com/zendframework/zend-expressive/blob/master/src/Application.php#L431-L435), not just individual matched params.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, added
$listener = new MiddlewareListener(); | ||
$return = $listener->onDispatch($event); | ||
self::assertInstanceOf(Response::class, $return); | ||
self::assertSame($matchedRouteParam, $return->getBody()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use $this->
(instead of self::
) in 2 above assertions to keep consistency with other tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Patch looks quite reasonable, and makes the support within middleware more on par with that in MVC controllers. 👍
…-attributes Add route match params to request attributes
Proposed change copies the
RouteMatch
parameters into the PSR-7\Zend\Diactoros\ServerRequest
so that they may be referred to in a middleware that has been invoked by theMiddlewareListener
. Currently, if using a middleware in this way, I don't see any other way to access the matched route information (specifically, matched route parameters from a segment route, e.g./:uuid
matches, but I can't access theuuid
parameter anywhere in the middleware action).