@@ -256,10 +256,15 @@ private function compileStaticRoutes(array $staticRoutes, bool $matchHost): stri
256256 }
257257
258258 if (!$ route ->getCondition ()) {
259+ $ defaults = $ route ->getDefaults ();
260+ if (isset ($ defaults ['_canonical_route ' ])) {
261+ $ name = $ defaults ['_canonical_route ' ];
262+ unset($ defaults ['_canonical_route ' ]);
263+ }
259264 $ default .= sprintf (
260265 "%s => array(%s, %s, %s, %s), \n" ,
261266 self ::export ($ url ),
262- self ::export (array ('_route ' => $ name ) + $ route -> getDefaults () ),
267+ self ::export (array ('_route ' => $ name ) + $ defaults ),
263268 self ::export (!$ route ->compile ()->getHostVariables () ? $ route ->getHost () : $ route ->compile ()->getHostRegex () ?: null ),
264269 self ::export (array_flip ($ route ->getMethods ()) ?: null ),
265270 self ::export (array_flip ($ route ->getSchemes ()) ?: null )
@@ -490,10 +495,15 @@ private function compileStaticPrefixCollection(StaticPrefixCollection $tree, \st
490495
491496 if (!$ route ->getCondition () && (!is_array ($ next = $ routes [1 + $ i ] ?? null ) || $ regex !== $ next [1 ])) {
492497 $ prevRegex = null ;
498+ $ defaults = $ route ->getDefaults ();
499+ if (isset ($ defaults ['_canonical_route ' ])) {
500+ $ name = $ defaults ['_canonical_route ' ];
501+ unset($ defaults ['_canonical_route ' ]);
502+ }
493503 $ state ->default .= sprintf (
494504 "%s => array(%s, %s, %s, %s), \n" ,
495505 $ state ->mark ,
496- self ::export (array ('_route ' => $ name ) + $ route -> getDefaults () ),
506+ self ::export (array ('_route ' => $ name ) + $ defaults ),
497507 self ::export ($ vars ),
498508 self ::export (array_flip ($ route ->getMethods ()) ?: null ),
499509 self ::export (array_flip ($ route ->getSchemes ()) ?: null )
@@ -619,6 +629,11 @@ private function compileRoute(Route $route, string $name, bool $checkHost): stri
619629
620630 // the offset where the return value is appended below, with indendation
621631 $ retOffset = 12 + strlen ($ code );
632+ $ defaults = $ route ->getDefaults ();
633+ if (isset ($ defaults ['_canonical_route ' ])) {
634+ $ name = $ defaults ['_canonical_route ' ];
635+ unset($ defaults ['_canonical_route ' ]);
636+ }
622637
623638 // optimize parameters array
624639 if ($ matches || $ hostMatches ) {
@@ -633,10 +648,10 @@ private function compileRoute(Route $route, string $name, bool $checkHost): stri
633648 $ code .= sprintf (
634649 " \$ret = \$this->mergeDefaults(%s, %s); \n" ,
635650 implode (' + ' , $ vars ),
636- self ::export ($ route -> getDefaults () )
651+ self ::export ($ defaults )
637652 );
638- } elseif ($ route -> getDefaults () ) {
639- $ code .= sprintf (" \$ret = %s; \n" , self ::export (array_replace ( $ route -> getDefaults (), array ('_route ' => $ name )) ));
653+ } elseif ($ defaults ) {
654+ $ code .= sprintf (" \$ret = %s; \n" , self ::export (array ('_route ' => $ name ) + $ defaults ));
640655 } else {
641656 $ code .= sprintf (" \$ret = array('_route' => '%s'); \n" , $ name );
642657 }
0 commit comments