Skip to content
This repository has been archived by the owner. It is now read-only.

Add route match params to request attributes #210

Conversation

@asgrim
Copy link
Contributor

@asgrim asgrim commented Dec 12, 2016

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 the MiddlewareListener. 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 the uuid parameter anywhere in the middleware action).

asgrim added 2 commits Dec 12, 2016
…ttributes
@asgrim asgrim force-pushed the asgrim:add-route-match-params-to-request-attributes branch from 9abe66e to 79fe956 Dec 13, 2016
@akrabat
Copy link
Contributor

@akrabat akrabat commented Dec 19, 2016

Looks good to me.

Copy link
Member

@michalbundyra michalbundyra left a comment

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) {

This comment has been minimized.

@michalbundyra

michalbundyra Dec 19, 2016
Member

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.

This comment has been minimized.

@asgrim

asgrim Dec 19, 2016
Author Contributor

Thanks, added

$listener = new MiddlewareListener();
$return = $listener->onDispatch($event);
self::assertInstanceOf(Response::class, $return);
self::assertSame($matchedRouteParam, $return->getBody());

This comment has been minimized.

@michalbundyra

michalbundyra Dec 19, 2016
Member

Please use $this-> (instead of self::) in 2 above assertions to keep consistency with other tests.

This comment has been minimized.

@asgrim

asgrim Dec 19, 2016
Author Contributor

Updated

Copy link
Member

@weierophinney weierophinney left a comment

Patch looks quite reasonable, and makes the support within middleware more on par with that in MVC controllers. 👍

@akrabat akrabat merged commit 05f3e6f into zendframework:master Dec 20, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.03%) to 83.129%
Details
akrabat added a commit that referenced this pull request Dec 20, 2016
…-attributes

Add route match params to request attributes
akrabat added a commit that referenced this pull request Dec 20, 2016
akrabat added a commit that referenced this pull request Dec 20, 2016
Close #210
akrabat added a commit that referenced this pull request Dec 20, 2016
Forward port #210
@akrabat akrabat added this to the 3.0.4 milestone Dec 20, 2016
akrabat added a commit that referenced this pull request Dec 20, 2016
Added
-----

- Nothing.

Deprecated
----------

- Nothing.

Removed
-------

- Nothing.

Fixed
-----

- [#210](#210) copies the
  `RouteMatch` and its parameters to the PSR-7 `ServerRequest` object so
  that they are available to middleware.
@asgrim asgrim deleted the asgrim:add-route-match-params-to-request-attributes branch Dec 20, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.