diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index fb147bced5..12aa644694 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -294,7 +294,7 @@ EOF; } // optimize parameters array - if (($matches || $hostnameMatches) && $route->getDefaults()) { + if ($matches || $hostnameMatches) { $vars = array(); if ($hostnameMatches) { $vars[] = '$hostnameMatches'; @@ -307,16 +307,6 @@ EOF; $code .= sprintf(" return \$this->mergeDefaults(array_replace(%s), %s);\n" , implode(', ', $vars), str_replace("\n", '', var_export($route->getDefaults(), true))); - } elseif ($matches || $hostnameMatches) { - - if (!$matches) { - $code .= " \$matches = \$hostnameMatches;\n"; - } elseif ($hostnameMatches) { - $code .= " \$matches = array_replace(\$hostnameMatches, \$matches);\n"; - } - - $code .= sprintf(" \$matches['_route'] = '%s';\n\n", $name); - $code .= " return \$matches;\n"; } elseif ($route->getDefaults()) { $code .= sprintf(" return %s;\n", str_replace("\n", '', var_export(array_replace($route->getDefaults(), array('_route' => $name)), true))); } else { diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php index 98d3cce44e..19ed9ca13f 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php @@ -38,9 +38,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher goto not_bar; } - $matches['_route'] = 'bar'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ()); } not_bar: @@ -51,9 +49,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher goto not_barhead; } - $matches['_route'] = 'barhead'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ()); } not_barhead: @@ -80,9 +76,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher // baz4 if (preg_match('#^/test/(?[^/]++)/$#s', $pathinfo, $matches)) { - $matches['_route'] = 'baz4'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ()); } // baz5 @@ -92,9 +86,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher goto not_baz5; } - $matches['_route'] = 'baz5'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ()); } not_baz5: @@ -105,9 +97,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher goto not_bazbaz6; } - $matches['_route'] = 'baz.baz6'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ()); } not_bazbaz6: @@ -120,9 +110,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher // quoter if (preg_match('#^/(?[\']+)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'quoter'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ()); } // space @@ -134,40 +122,30 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (0 === strpos($pathinfo, '/a/b\'b')) { // foo1 if (preg_match('#^/a/b\'b/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'foo1'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo1')), array ()); } // bar1 if (preg_match('#^/a/b\'b/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'bar1'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ()); } } // overridden if (preg_match('#^/a/(?.*)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'overridden'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'overridden')), array ()); } if (0 === strpos($pathinfo, '/a/b\'b')) { // foo2 if (preg_match('#^/a/b\'b/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'foo2'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo2')), array ()); } // bar2 if (preg_match('#^/a/b\'b/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'bar2'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ()); } } @@ -194,16 +172,12 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher // foo3 if (preg_match('#^/(?<_locale>[^/]++)/b/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'foo3'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ()); } // bar3 if (preg_match('#^/(?<_locale>[^/]++)/b/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'bar3'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar3')), array ()); } if (0 === strpos($pathinfo, '/aba')) { @@ -214,9 +188,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher // foo4 if (preg_match('#^/aba/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'foo4'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ()); } } @@ -269,10 +241,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (0 === strpos($pathinfo, '/route1')) { // route11 if ($pathinfo === '/route11') { - $matches = $hostnameMatches; - $matches['_route'] = 'route11'; - - return $matches; + return $this->mergeDefaults(array_replace($hostnameMatches, array('_route' => 'route11')), array ()); } // route12 @@ -282,10 +251,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher // route13 if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches = array_replace($hostnameMatches, $matches); - $matches['_route'] = 'route13'; - - return $matches; + return $this->mergeDefaults(array_replace($hostnameMatches, $matches, array('_route' => 'route13')), array ()); } // route14 @@ -300,9 +266,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (preg_match('#^c\\.example\\.com$#s', $hostname, $hostnameMatches)) { // route15 if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'route15'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ()); } } @@ -329,16 +293,12 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (0 === strpos($pathinfo, '/a/b')) { // b if (preg_match('#^/a/b/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'b'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ()); } // c if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'c'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ()); } } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php index f4de7eb1b2..6063042d0d 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php @@ -38,9 +38,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec goto not_bar; } - $matches['_route'] = 'bar'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ()); } not_bar: @@ -51,9 +49,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec goto not_barhead; } - $matches['_route'] = 'barhead'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ()); } not_barhead: @@ -88,9 +84,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec return $this->redirect($pathinfo.'/', 'baz4'); } - $matches['_route'] = 'baz4'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ()); } // baz5 @@ -100,9 +94,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec goto not_baz5; } - $matches['_route'] = 'baz5'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ()); } not_baz5: @@ -113,9 +105,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec goto not_bazbaz6; } - $matches['_route'] = 'baz.baz6'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ()); } not_bazbaz6: @@ -128,9 +118,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec // quoter if (preg_match('#^/(?[\']+)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'quoter'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ()); } // space @@ -142,40 +130,30 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if (0 === strpos($pathinfo, '/a/b\'b')) { // foo1 if (preg_match('#^/a/b\'b/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'foo1'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo1')), array ()); } // bar1 if (preg_match('#^/a/b\'b/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'bar1'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ()); } } // overridden if (preg_match('#^/a/(?.*)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'overridden'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'overridden')), array ()); } if (0 === strpos($pathinfo, '/a/b\'b')) { // foo2 if (preg_match('#^/a/b\'b/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'foo2'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo2')), array ()); } // bar2 if (preg_match('#^/a/b\'b/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'bar2'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ()); } } @@ -206,16 +184,12 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec // foo3 if (preg_match('#^/(?<_locale>[^/]++)/b/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'foo3'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ()); } // bar3 if (preg_match('#^/(?<_locale>[^/]++)/b/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'bar3'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar3')), array ()); } if (0 === strpos($pathinfo, '/aba')) { @@ -226,9 +200,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec // foo4 if (preg_match('#^/aba/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'foo4'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ()); } } @@ -281,10 +253,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if (0 === strpos($pathinfo, '/route1')) { // route11 if ($pathinfo === '/route11') { - $matches = $hostnameMatches; - $matches['_route'] = 'route11'; - - return $matches; + return $this->mergeDefaults(array_replace($hostnameMatches, array('_route' => 'route11')), array ()); } // route12 @@ -294,10 +263,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec // route13 if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches = array_replace($hostnameMatches, $matches); - $matches['_route'] = 'route13'; - - return $matches; + return $this->mergeDefaults(array_replace($hostnameMatches, $matches, array('_route' => 'route13')), array ()); } // route14 @@ -312,9 +278,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if (preg_match('#^c\\.example\\.com$#s', $hostname, $hostnameMatches)) { // route15 if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'route15'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ()); } } @@ -341,16 +305,12 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if (0 === strpos($pathinfo, '/a/b')) { // b if (preg_match('#^/a/b/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'b'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ()); } // c if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'c'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ()); } } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php index a0b1320a76..7dbdffef85 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php @@ -33,9 +33,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher // dynamic if (preg_match('#^/rootprefix/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches['_route'] = 'dynamic'; - - return $matches; + return $this->mergeDefaults(array_replace($matches, array('_route' => 'dynamic')), array ()); } }