File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public function __invoke(
36
36
): ResponseInterface {
37
37
// Inject the request and response by parameter name
38
38
$ parameters = [
39
- 'request ' => $ request ,
39
+ 'request ' => self :: injectRouteArguments ( $ request, $ routeArguments ) ,
40
40
'response ' => $ response ,
41
41
];
42
42
// Inject the route arguments by name
@@ -46,4 +46,13 @@ public function __invoke(
46
46
47
47
return $ this ->invoker ->call ($ callable , $ parameters );
48
48
}
49
+
50
+ private static function injectRouteArguments (ServerRequestInterface $ request , array $ routeArguments ): ServerRequestInterface
51
+ {
52
+ $ requestWithArgs = $ request ;
53
+ foreach ($ routeArguments as $ key => $ value ) {
54
+ $ requestWithArgs = $ requestWithArgs ->withAttribute ($ key , $ value );
55
+ }
56
+ return $ requestWithArgs ;
57
+ }
49
58
}
Original file line number Diff line number Diff line change @@ -44,6 +44,21 @@ public function injects_route_placeholder()
44
44
$ this ->assertEquals ('Hello matt ' , (string ) $ response ->getBody ());
45
45
}
46
46
47
+ /**
48
+ * @test
49
+ */
50
+ public function injects_route_placeholder_from_request ()
51
+ {
52
+ $ app = Bridge::create ();
53
+ $ app ->get ('/{name} ' , function ($ request , $ response ) {
54
+ $ response ->getBody ()->write ('Hello ' . $ request ->getAttribute ('name ' ));
55
+ return $ response ;
56
+ });
57
+
58
+ $ response = $ app ->handle (RequestFactory::create ('/matt ' ));
59
+ $ this ->assertEquals ('Hello matt ' , (string ) $ response ->getBody ());
60
+ }
61
+
47
62
/**
48
63
* @test
49
64
*/
You can’t perform that action at this time.
0 commit comments