Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 79fe956

Browse files
committed
Copy route match params into PSR-7 request attributes
1 parent e84fbfa commit 79fe956

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Diff for: src/MiddlewareListener.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ public function onDispatch(MvcEvent $event)
5959

6060
$caughtException = null;
6161
try {
62-
$return = $middleware(Psr7Request::fromZend($request), Psr7Response::fromZend($response));
62+
$psr7Request = Psr7Request::fromZend($request);
63+
foreach ($routeMatch->getParams() as $key => $value) {
64+
$psr7Request = $psr7Request->withAttribute($key, $value);
65+
}
66+
$return = $middleware($psr7Request, Psr7Response::fromZend($response));
6367
} catch (\Throwable $ex) {
6468
$caughtException = $ex;
6569
} catch (\Exception $ex) { // @TODO clean up once PHP 7 requirement is enforced

Diff for: test/MiddlewareListenerTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class MiddlewareListenerTest extends TestCase
2929
*/
3030
private $routeMatch;
3131

32-
3332
/**
3433
* Create an MvcEvent, populated with everything it needs.
3534
*
@@ -42,6 +41,7 @@ public function createMvcEvent($middlewareMatched, $middleware = null)
4241
$response = new Response();
4342
$this->routeMatch = $this->prophesize(RouteMatch::class);
4443
$this->routeMatch->getParam('middleware', false)->willReturn($middlewareMatched);
44+
$this->routeMatch->getParams()->willReturn([]);
4545

4646
$eventManager = new EventManager();
4747

@@ -153,6 +153,7 @@ public function testCanLoadFromAbstractFactory()
153153
$response = new Response();
154154
$routeMatch = $this->prophesize(RouteMatch::class);
155155
$routeMatch->getParam('middleware', false)->willReturn('test');
156+
$routeMatch->getParams()->willReturn([]);
156157

157158
$eventManager = new EventManager();
158159

0 commit comments

Comments
 (0)