Permalink
Browse files

[Routing] fix PhpMatcherDumper that returned numeric-indexed params t…

…hat are returned besides named placeholders by preg_match
  • Loading branch information...
Tobion authored and arnaud-lb committed Nov 11, 2012
1 parent 7ed3013 commit 514e27a5110dd28f1d9ab3fbfdb3ca93999c729a
@@ -294,7 +294,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
}
// optimize parameters array
- if (($matches || $hostnameMatches) && $route->getDefaults()) {
+ if ($matches || $hostnameMatches) {
$vars = array();
if ($hostnameMatches) {
$vars[] = '$hostnameMatches';
@@ -307,16 +307,6 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
$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 {
@@ -38,9 +38,7 @@ public function match($pathinfo)
goto not_bar;
}
- $matches['_route'] = 'bar';
-
- return $matches;
+ return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ());
}
not_bar:
@@ -51,9 +49,7 @@ public function match($pathinfo)
goto not_barhead;
}
- $matches['_route'] = 'barhead';
-
- return $matches;
+ return $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ());
}
not_barhead:
@@ -80,9 +76,7 @@ public function match($pathinfo)
// baz4
if (preg_match('#^/test/(?<foo>[^/]++)/$#s', $pathinfo, $matches)) {
- $matches['_route'] = 'baz4';
-
- return $matches;
+ return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ());
}
// baz5
@@ -92,9 +86,7 @@ public function match($pathinfo)
goto not_baz5;
}
- $matches['_route'] = 'baz5';
-
- return $matches;
+ return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ());
}
not_baz5:
@@ -105,9 +97,7 @@ public function match($pathinfo)
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 @@ public function match($pathinfo)
// quoter
if (preg_match('#^/(?<quoter>[\']+)$#s', $pathinfo, $matches)) {
- $matches['_route'] = 'quoter';
-
- return $matches;
+ return $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ());
}
// space
@@ -134,40 +122,30 @@ public function match($pathinfo)
if (0 === strpos($pathinfo, '/a/b\'b')) {
// foo1
if (preg_match('#^/a/b\'b/(?<foo>[^/]++)$#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/(?<bar>[^/]++)$#s', $pathinfo, $matches)) {
- $matches['_route'] = 'bar1';
-
- return $matches;
+ return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ());
}
}
// overridden
if (preg_match('#^/a/(?<var>.*)$#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/(?<foo1>[^/]++)$#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/(?<bar1>[^/]++)$#s', $pathinfo, $matches)) {
- $matches['_route'] = 'bar2';
-
- return $matches;
+ return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ());
}
}
@@ -194,16 +172,12 @@ public function match($pathinfo)
// foo3
if (preg_match('#^/(?<_locale>[^/]++)/b/(?<foo>[^/]++)$#s', $pathinfo, $matches)) {
- $matches['_route'] = 'foo3';
-
- return $matches;
+ return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ());
}
// bar3
if (preg_match('#^/(?<_locale>[^/]++)/b/(?<bar>[^/]++)$#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 @@ public function match($pathinfo)
// foo4
if (preg_match('#^/aba/(?<foo>[^/]++)$#s', $pathinfo, $matches)) {
- $matches['_route'] = 'foo4';
-
- return $matches;
+ return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ());
}
}
@@ -269,10 +241,7 @@ public function match($pathinfo)
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 @@ public function match($pathinfo)
// route13
if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?<name>[^/]++)$#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 @@ public function match($pathinfo)
if (preg_match('#^c\\.example\\.com$#s', $hostname, $hostnameMatches)) {
// route15
if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?<name>[^/]++)$#s', $pathinfo, $matches)) {
- $matches['_route'] = 'route15';
-
- return $matches;
+ return $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ());
}
}
@@ -329,16 +293,12 @@ public function match($pathinfo)
if (0 === strpos($pathinfo, '/a/b')) {
// b
if (preg_match('#^/a/b/(?<var>[^/]++)$#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/(?<var>[^/]++)$#s', $pathinfo, $matches)) {
- $matches['_route'] = 'c';
-
- return $matches;
+ return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ());
}
}
Oops, something went wrong.

0 comments on commit 514e27a

Please sign in to comment.