@@ -180,11 +180,12 @@ 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 = Request:: create ($ url );
183
+ $ requestForMatching = $ this -> rebuildRequest ($ url );
184
184
}
185
185
186
186
return $ router ->matchRequest ($ requestForMatching );
187
187
}
188
+
188
189
// every router implements the match method
189
190
return $ router ->match ($ url );
190
191
} catch (ResourceNotFoundException $ e ) {
@@ -249,6 +250,51 @@ public function generate($name, $parameters = array(), $absolute = UrlGeneratorI
249
250
throw new RouteNotFoundException (sprintf ('None of the chained routers were able to generate route: %s ' , $ info ));
250
251
}
251
252
253
+ /**
254
+ * Rebuild the request object from a URL with the help of the RequestContext.
255
+ *
256
+ * If the request context is not set, this simply returns the request object built from $uri.
257
+ *
258
+ * @param string $uri
259
+ *
260
+ * @return Request
261
+ */
262
+ private function rebuildRequest ($ uri )
263
+ {
264
+ if (!$ this ->context ) {
265
+ return Request::create ($ uri );
266
+ }
267
+
268
+ $ server = array ();
269
+ if ($ this ->context ->getHost ()) {
270
+ $ server ['SERVER_NAME ' ] = $ this ->context ->getHost ();
271
+ $ server ['HTTP_HOST ' ] = $ this ->context ->getHost ();
272
+ }
273
+ if ($ this ->context ->getBaseUrl ()) {
274
+ $ uri = $ this ->context ->getBaseUrl ().$ uri ;
275
+ $ server ['SCRIPT_FILENAME ' ] = $ this ->context ->getBaseUrl ();
276
+ $ server ['PHP_SELF ' ] = $ this ->context ->getBaseUrl ();
277
+ }
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
+ }
293
+ }
294
+
295
+ return Request::create ($ uri , $ this ->context ->getMethod (), $ this ->context ->getParameters (), array (), array (), $ server );
296
+ }
297
+
252
298
private function getErrorMessage ($ name , $ router = null , $ parameters = null )
253
299
{
254
300
if ($ router instanceof VersatileGeneratorInterface) {
0 commit comments