diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index 6abca6ac71..7fb66a6124 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -153,14 +153,14 @@ abstract class AnnotationClassLoader implements LoaderInterface $name = $this->getDefaultRouteName($class, $method); } - $defaults = array_merge($globals['defaults'], $annot->getDefaults()); + $defaults = array_replace($globals['defaults'], $annot->getDefaults()); foreach ($method->getParameters() as $param) { if ($param->isOptional()) { $defaults[$param->getName()] = $param->getDefaultValue(); } } - $requirements = array_merge($globals['requirements'], $annot->getRequirements()); - $options = array_merge($globals['options'], $annot->getOptions()); + $requirements = array_replace($globals['requirements'], $annot->getRequirements()); + $options = array_replace($globals['options'], $annot->getOptions()); $hostnamePattern = $annot->getHostnamePattern(); if (null === $hostnamePattern) { diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index 18c1f9ce96..fb147bced5 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -37,7 +37,7 @@ class PhpMatcherDumper extends MatcherDumper */ public function dump(array $options = array()) { - $options = array_merge(array( + $options = array_replace(array( 'class' => 'ProjectUrlMatcher', 'base_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher', ), $options); @@ -296,35 +296,29 @@ EOF; // optimize parameters array if (($matches || $hostnameMatches) && $route->getDefaults()) { $vars = array(); - if ($matches) { - $vars[] = '$matches'; - } if ($hostnameMatches) { $vars[] = '$hostnameMatches'; } - if (count($vars) > 1) { - $matchesExpr = 'array_merge(' . implode(', ', array_reverse($vars)) . ')'; - } else { - $matchesExpr = current($vars); + if ($matches) { + $vars[] = '$matches'; } + $vars[] = "array('_route' => '$name')"; - $code .= sprintf(" return array_merge(\$this->mergeDefaults(%s, %s), array('_route' => '%s'));\n" - , $matchesExpr, str_replace("\n", '', var_export($route->getDefaults(), true)), $name); + $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"; - } else { - if ($hostnameMatches) { - $code .= " \$matches = array_merge(\$hostnameMatches, \$matches);\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_merge($route->getDefaults(), array('_route' => $name)), true))); + $code .= sprintf(" return %s;\n", str_replace("\n", '', var_export(array_replace($route->getDefaults(), array('_route' => $name)), true))); } else { $code .= sprintf(" return array('_route' => '%s');\n", $name); } diff --git a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php index 26812edb43..2afe0f738e 100644 --- a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php @@ -117,8 +117,8 @@ class UrlMatcher implements UrlMatcherInterface if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) { continue; } - $hostnameMatches = array(); + $hostnameMatches = array(); if ($compiledRoute->getHostnameRegex() && !preg_match($compiledRoute->getHostnameRegex(), $this->context->getHost(), $hostnameMatches)) { continue; } @@ -147,7 +147,7 @@ class UrlMatcher implements UrlMatcherInterface continue; } - return array_merge($this->mergeDefaults(array_merge($matches, $hostnameMatches), $route->getDefaults()), array('_route' => $name)); + return $this->mergeDefaults(array_replace($matches, $hostnameMatches, array('_route' => $name)), $route->getDefaults()); } } 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 dec8ba4a40..98d3cce44e 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php @@ -27,7 +27,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher // foo if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?baz|symfony)$#s', $pathinfo, $matches)) { - return array_merge($this->mergeDefaults($matches, array ( 'def' => 'test',)), array('_route' => 'foo')); + return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',)); } if (0 === strpos($pathinfo, '/bar')) { @@ -177,7 +177,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (0 === strpos($pathinfo, '/multi')) { // helloWorld if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?[^/]++))?$#s', $pathinfo, $matches)) { - return array_merge($this->mergeDefaults($matches, array ( 'who' => 'World!',)), array('_route' => 'helloWorld')); + return $this->mergeDefaults(array_replace($matches, array('_route' => 'helloWorld')), array ( 'who' => 'World!',)); } // overridden2 @@ -277,12 +277,12 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher // route12 if ($pathinfo === '/route12') { - return array_merge($this->mergeDefaults($hostnameMatches, array ( 'var1' => 'val',)), array('_route' => 'route12')); + return $this->mergeDefaults(array_replace($hostnameMatches, array('_route' => 'route12')), array ( 'var1' => 'val',)); } // route13 if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches = array_merge($hostnameMatches, $matches); + $matches = array_replace($hostnameMatches, $matches); $matches['_route'] = 'route13'; return $matches; @@ -290,7 +290,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher // route14 if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?[^/]++)$#s', $pathinfo, $matches)) { - return array_merge($this->mergeDefaults(array_merge($hostnameMatches, $matches), array ( 'var1' => 'val',)), array('_route' => 'route14')); + return $this->mergeDefaults(array_replace($hostnameMatches, $matches, array('_route' => 'route14')), array ( 'var1' => 'val',)); } } @@ -310,7 +310,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (0 === strpos($pathinfo, '/route1')) { // route16 if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?[^/]++)$#s', $pathinfo, $matches)) { - return array_merge($this->mergeDefaults($matches, array ( 'var1' => 'val',)), array('_route' => 'route16')); + return $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',)); } // route17 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 607b53fb1d..f4de7eb1b2 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php @@ -27,7 +27,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec // foo if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?baz|symfony)$#s', $pathinfo, $matches)) { - return array_merge($this->mergeDefaults($matches, array ( 'def' => 'test',)), array('_route' => 'foo')); + return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',)); } if (0 === strpos($pathinfo, '/bar')) { @@ -185,7 +185,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if (0 === strpos($pathinfo, '/multi')) { // helloWorld if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?[^/]++))?$#s', $pathinfo, $matches)) { - return array_merge($this->mergeDefaults($matches, array ( 'who' => 'World!',)), array('_route' => 'helloWorld')); + return $this->mergeDefaults(array_replace($matches, array('_route' => 'helloWorld')), array ( 'who' => 'World!',)); } // overridden2 @@ -289,12 +289,12 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec // route12 if ($pathinfo === '/route12') { - return array_merge($this->mergeDefaults($hostnameMatches, array ( 'var1' => 'val',)), array('_route' => 'route12')); + return $this->mergeDefaults(array_replace($hostnameMatches, array('_route' => 'route12')), array ( 'var1' => 'val',)); } // route13 if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?[^/]++)$#s', $pathinfo, $matches)) { - $matches = array_merge($hostnameMatches, $matches); + $matches = array_replace($hostnameMatches, $matches); $matches['_route'] = 'route13'; return $matches; @@ -302,7 +302,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec // route14 if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?[^/]++)$#s', $pathinfo, $matches)) { - return array_merge($this->mergeDefaults(array_merge($hostnameMatches, $matches), array ( 'var1' => 'val',)), array('_route' => 'route14')); + return $this->mergeDefaults(array_replace($hostnameMatches, $matches, array('_route' => 'route14')), array ( 'var1' => 'val',)); } } @@ -322,7 +322,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec if (0 === strpos($pathinfo, '/route1')) { // route16 if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?[^/]++)$#s', $pathinfo, $matches)) { - return array_merge($this->mergeDefaults($matches, array ( 'var1' => 'val',)), array('_route' => 'route16')); + return $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',)); } // route17