@@ -286,10 +286,32 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
286
286
}
287
287
}
288
288
289
+ // optimize parameters array
290
+ if ($ matches || $ hostMatches ) {
291
+ $ vars = array ();
292
+ if ($ hostMatches ) {
293
+ $ vars [] = '$hostMatches ' ;
294
+ }
295
+ if ($ matches ) {
296
+ $ vars [] = '$matches ' ;
297
+ }
298
+ $ vars [] = "array('_route' => ' $ name') " ;
299
+
300
+ $ code .= sprintf (
301
+ " \$ret = \$this->mergeDefaults(array_replace(%s), %s); \n" ,
302
+ implode (', ' , $ vars ),
303
+ str_replace ("\n" , '' , var_export ($ route ->getDefaults (), true ))
304
+ );
305
+ } elseif ($ route ->getDefaults ()) {
306
+ $ code .= sprintf (" \$ret = %s; \n" , str_replace ("\n" , '' , var_export (array_replace ($ route ->getDefaults (), array ('_route ' => $ name )), true )));
307
+ } else {
308
+ $ code .= sprintf (" \$ret = array('_route' => '%s'); \n" , $ name );
309
+ }
310
+
289
311
if ($ hasTrailingSlash ) {
290
312
$ code .= <<<EOF
291
313
if (substr( \$pathinfo, -1) !== '/') {
292
- return \$ this->redirect( \$pathinfo.'/', ' $ name');
314
+ return array_replace( \$ ret, \$ this->redirect( \$pathinfo.'/', ' $ name') );
293
315
}
294
316
295
317
@@ -304,34 +326,14 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
304
326
$ code .= <<<EOF
305
327
\$requiredSchemes = $ schemes;
306
328
if (!isset( \$requiredSchemes[ \$this->context->getScheme()])) {
307
- return \$ this->redirect( \$pathinfo, ' $ name', key( \$requiredSchemes));
329
+ return array_replace( \$ ret, \$ this->redirect( \$pathinfo, ' $ name', key( \$requiredSchemes) ));
308
330
}
309
331
310
332
311
333
EOF ;
312
334
}
313
335
314
- // optimize parameters array
315
- if ($ matches || $ hostMatches ) {
316
- $ vars = array ();
317
- if ($ hostMatches ) {
318
- $ vars [] = '$hostMatches ' ;
319
- }
320
- if ($ matches ) {
321
- $ vars [] = '$matches ' ;
322
- }
323
- $ vars [] = "array('_route' => ' $ name') " ;
324
-
325
- $ code .= sprintf (
326
- " return \$this->mergeDefaults(array_replace(%s), %s); \n" ,
327
- implode (', ' , $ vars ),
328
- str_replace ("\n" , '' , var_export ($ route ->getDefaults (), true ))
329
- );
330
- } elseif ($ route ->getDefaults ()) {
331
- $ code .= sprintf (" return %s; \n" , str_replace ("\n" , '' , var_export (array_replace ($ route ->getDefaults (), array ('_route ' => $ name )), true )));
332
- } else {
333
- $ code .= sprintf (" return array('_route' => '%s'); \n" , $ name );
334
- }
336
+ $ code .= " return \$ret; \n" ;
335
337
$ code .= " } \n" ;
336
338
337
339
if ($ methods ) {
0 commit comments