-
Notifications
You must be signed in to change notification settings - Fork 89
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. |
michalbundyra
left a comment
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).
| 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
test/MiddlewareListenerTest.php
Outdated
| $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
weierophinney
left a comment
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
RouteMatchparameters into the PSR-7\Zend\Diactoros\ServerRequestso 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./:uuidmatches, but I can't access theuuidparameter anywhere in the middleware action).