@@ -141,9 +141,9 @@ protected function sortRouters()
141
141
*
142
142
* Note: You should use matchRequest if you can.
143
143
*/
144
- public function match ($ url )
144
+ public function match ($ pathinfo )
145
145
{
146
- return $ this ->doMatch ($ url );
146
+ return $ this ->doMatch ($ pathinfo );
147
147
}
148
148
149
149
/**
@@ -162,14 +162,14 @@ public function matchRequest(Request $request)
162
162
* At least the url must be provided, if a request is additionally provided
163
163
* the request takes precedence.
164
164
*
165
- * @param string $url
165
+ * @param string $pathinfo
166
166
* @param Request $request
167
167
*
168
168
* @return array An array of parameters
169
169
*
170
170
* @throws ResourceNotFoundException If no router matched.
171
171
*/
172
- private function doMatch ($ url , Request $ request = null )
172
+ private function doMatch ($ pathinfo , Request $ request = null )
173
173
{
174
174
$ methodNotAllowed = null ;
175
175
@@ -180,14 +180,14 @@ private function doMatch($url, Request $request = null)
180
180
// matching requests is more powerful than matching URLs only, so try that first
181
181
if ($ router instanceof RequestMatcherInterface) {
182
182
if (empty ($ requestForMatching )) {
183
- $ requestForMatching = $ this ->rebuildRequest ($ url );
183
+ $ requestForMatching = $ this ->rebuildRequest ($ pathinfo );
184
184
}
185
185
186
186
return $ router ->matchRequest ($ requestForMatching );
187
187
}
188
188
189
189
// every router implements the match method
190
- return $ router ->match ($ url );
190
+ return $ router ->match ($ pathinfo );
191
191
} catch (ResourceNotFoundException $ e ) {
192
192
if ($ this ->logger ) {
193
193
$ this ->logger ->debug ('Router ' .get_class ($ router ).' was not able to match, message " ' .$ e ->getMessage ().'" ' );
@@ -203,7 +203,7 @@ private function doMatch($url, Request $request = null)
203
203
204
204
$ info = $ request
205
205
? "this request \n$ request "
206
- : "url ' $ url ' " ;
206
+ : "url ' $ pathinfo ' " ;
207
207
throw $ methodNotAllowed ?: new ResourceNotFoundException ("None of the routers in the chain matched $ info " );
208
208
}
209
209
@@ -255,42 +255,32 @@ public function generate($name, $parameters = array(), $absolute = UrlGeneratorI
255
255
*
256
256
* If the request context is not set, this simply returns the request object built from $uri.
257
257
*
258
- * @param string $uri
258
+ * @param string $pathinfo
259
259
*
260
260
* @return Request
261
261
*/
262
- private function rebuildRequest ($ uri )
262
+ private function rebuildRequest ($ pathinfo )
263
263
{
264
264
if (!$ this ->context ) {
265
- return Request::create ($ uri );
265
+ return Request::create (' http://localhost ' . $ pathinfo );
266
266
}
267
267
268
+ $ uri = $ pathinfo ;
269
+
268
270
$ server = array ();
269
- if ($ this ->context ->getHost ()) {
270
- $ server ['SERVER_NAME ' ] = $ this ->context ->getHost ();
271
- $ server ['HTTP_HOST ' ] = $ this ->context ->getHost ();
272
- }
273
271
if ($ this ->context ->getBaseUrl ()) {
274
- $ uri = $ this ->context ->getBaseUrl ().$ uri ;
272
+ $ uri = $ this ->context ->getBaseUrl ().$ pathinfo ;
275
273
$ server ['SCRIPT_FILENAME ' ] = $ this ->context ->getBaseUrl ();
276
274
$ server ['PHP_SELF ' ] = $ this ->context ->getBaseUrl ();
277
275
}
278
- if ('https ' === $ this ->context ->getScheme ()) {
279
- $ server ['HTTPS ' ] = 'on ' ;
280
- $ server ['SERVER_PORT ' ] = $ this ->context ->getHttpsPort ();
281
- if (443 !== $ this ->context ->getHttpsPort ()) {
282
- // this is parsed from the host by symfony request
283
- // https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php#L971
284
- $ server ['HTTP_HOST ' ] .= ': ' .$ this ->context ->getHttpsPort ();
285
- }
286
- } else {
287
- $ server ['SERVER_PORT ' ] = $ this ->context ->getHttpPort ();
288
- if (80 !== $ this ->context ->getHttpPort ()) {
289
- // this is parsed from the host by symfony request
290
- // https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php#L971
291
- $ server ['HTTP_HOST ' ] .= ': ' .$ this ->context ->getHttpPort ();
292
- }
276
+ $ host = $ this ->context ->getHost () ?: 'localhost ' ;
277
+ if ('https ' === $ this ->context ->getScheme () && 443 !== $ this ->context ->getHttpsPort ()) {
278
+ $ host .= ': ' .$ this ->context ->getHttpsPort ();
279
+ }
280
+ if ('http ' === $ this ->context ->getScheme () && 80 !== $ this ->context ->getHttpPort ()) {
281
+ $ host .= ': ' .$ this ->context ->getHttpPort ();
293
282
}
283
+ $ uri = $ this ->context ->getScheme ().':// ' .$ host .$ uri .$ this ->context ->getQueryString ();
294
284
295
285
return Request::create ($ uri , $ this ->context ->getMethod (), $ this ->context ->getParameters (), array (), array (), $ server );
296
286
}
0 commit comments