This repository was archived by the owner on Jan 29, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +24
-7
lines changed Expand file tree Collapse file tree 1 file changed +24
-7
lines changed Original file line number Diff line number Diff line change 10
10
namespace Zend \Mvc \Controller ;
11
11
12
12
use Psr \Http \Message \ResponseInterface ;
13
+ use Psr \Http \Message \ServerRequestInterface ;
13
14
use Zend \EventManager \EventManager ;
14
15
use Zend \Http \Request ;
15
16
use Zend \Http \Response ;
@@ -80,13 +81,10 @@ public function onDispatch(MvcEvent $e)
80
81
}
81
82
82
83
$ routeMatch = $ e ->getRouteMatch ();
83
- $ psr7Request = Psr7ServerRequest::fromZend ($ request )->withAttribute (RouteMatch::class, $ routeMatch );
84
-
85
- if ($ routeMatch ) {
86
- foreach ($ routeMatch ->getParams () as $ key => $ value ) {
87
- $ psr7Request = $ psr7Request ->withAttribute ($ key , $ value );
88
- }
89
- }
84
+ $ psr7Request = $ this ->populateRequestParametersFromRoute (
85
+ Psr7ServerRequest::fromZend ($ request )->withAttribute (RouteMatch::class, $ routeMatch ),
86
+ $ routeMatch
87
+ );
90
88
91
89
$ result = $ this ->pipe ->process ($ psr7Request , new CallableDelegateDecorator (
92
90
function () {
@@ -99,4 +97,23 @@ function () {
99
97
100
98
return $ result ;
101
99
}
100
+
101
+ /**
102
+ * @param ServerRequestInterface $request
103
+ * @param RouteMatch|null $routeMatch
104
+ *
105
+ * @return ServerRequestInterface
106
+ */
107
+ private function populateRequestParametersFromRoute (ServerRequestInterface $ request , RouteMatch $ routeMatch = null )
108
+ {
109
+ if (! $ routeMatch ) {
110
+ return $ request ;
111
+ }
112
+
113
+ foreach ($ routeMatch ->getParams () as $ key => $ value ) {
114
+ $ request = $ request ->withAttribute ($ key , $ value );
115
+ }
116
+
117
+ return $ request ;
118
+ }
102
119
}
You can’t perform that action at this time.
0 commit comments