diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index 605ee560ebc88..199f941159fba 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -270,10 +270,28 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren } } + // optimize parameters array + if ($matches || $hostMatches) { + $vars = array(); + if ($hostMatches) { + $vars[] = '$hostMatches'; + } + if ($matches) { + $vars[] = '$matches'; + } + $vars[] = "array('_route' => '$name')"; + + $code .= sprintf(" \$ret = \$this->mergeDefaults(array_replace(%s), %s);\n", implode(', ', $vars), str_replace("\n", '', var_export($route->getDefaults(), true))); + } elseif ($route->getDefaults()) { + $code .= sprintf(" \$ret = %s;\n", str_replace("\n", '', var_export(array_replace($route->getDefaults(), array('_route' => $name)), true))); + } else { + $code .= sprintf(" \$ret = array('_route' => '%s');\n", $name); + } + if ($hasTrailingSlash) { $code .= <<redirect(\$pathinfo.'/', '$name'); + return array_replace(\$ret, \$this->redirect(\$pathinfo.'/', '$name')); } @@ -287,30 +305,13 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren $code .= <<context->getScheme() !== '$scheme') { - return \$this->redirect(\$pathinfo, '$name', '$scheme'); + return array_replace(\$ret, \$this->redirect(\$pathinfo, '$name', '$scheme')); } EOF; } - - // optimize parameters array - if ($matches || $hostMatches) { - $vars = array(); - if ($hostMatches) { - $vars[] = '$hostMatches'; - } - if ($matches) { - $vars[] = '$matches'; - } - $vars[] = "array('_route' => '$name')"; - - $code .= sprintf(" return \$this->mergeDefaults(array_replace(%s), %s);\n", implode(', ', $vars), str_replace("\n", '', var_export($route->getDefaults(), true))); - } elseif ($route->getDefaults()) { - $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); - } + $code .= " return \$ret;\n"; $code .= " }\n"; if ($methods) { diff --git a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php index 5bd68b39957ec..5df7f9f2b0541 100644 --- a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php @@ -134,7 +134,9 @@ protected function matchCollection($pathinfo, RouteCollection $routes) $status = $this->handleRouteRequirements($pathinfo, $name, $route); if (self::ROUTE_MATCH === $status[0]) { - return $status[1]; + $attributes = array_replace($matches, $hostMatches, (array) $status[1]); + + return $this->mergeDefaults($attributes, $route->getDefaults()); } if (self::REQUIREMENT_MISMATCH === $status[0]) { 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 2ef0376666ad3..6db6c3e994203 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,8 @@ public function match($pathinfo) // foo if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?Pbaz|symfony)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',)); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',)); + return $ret; } if (0 === strpos($pathinfo, '/bar')) { @@ -38,7 +39,8 @@ public function match($pathinfo) goto not_bar; } - return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ()); + return $ret; } not_bar: @@ -49,7 +51,8 @@ public function match($pathinfo) goto not_barhead; } - return $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ()); + return $ret; } not_barhead: @@ -59,24 +62,28 @@ public function match($pathinfo) if (0 === strpos($pathinfo, '/test/baz')) { // baz if ($pathinfo === '/test/baz') { - return array('_route' => 'baz'); + $ret = array('_route' => 'baz'); + return $ret; } // baz2 if ($pathinfo === '/test/baz.html') { - return array('_route' => 'baz2'); + $ret = array('_route' => 'baz2'); + return $ret; } // baz3 if ($pathinfo === '/test/baz3/') { - return array('_route' => 'baz3'); + $ret = array('_route' => 'baz3'); + return $ret; } } // baz4 if (preg_match('#^/test/(?P[^/]++)/$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ()); + return $ret; } // baz5 @@ -86,7 +93,8 @@ public function match($pathinfo) goto not_baz5; } - return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ()); + return $ret; } not_baz5: @@ -97,7 +105,8 @@ public function match($pathinfo) goto not_bazbaz6; } - return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ()); + return $ret; } not_bazbaz6: @@ -105,47 +114,55 @@ public function match($pathinfo) // foofoo if ($pathinfo === '/foofoo') { - return array ( 'def' => 'test', '_route' => 'foofoo',); + $ret = array ( 'def' => 'test', '_route' => 'foofoo',); + return $ret; } // quoter if (preg_match('#^/(?P[\']+)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ()); + return $ret; } // space if ($pathinfo === '/spa ce') { - return array('_route' => 'space'); + $ret = array('_route' => 'space'); + return $ret; } if (0 === strpos($pathinfo, '/a')) { if (0 === strpos($pathinfo, '/a/b\'b')) { // foo1 if (preg_match('#^/a/b\'b/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo1')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'foo1')), array ()); + return $ret; } // bar1 if (preg_match('#^/a/b\'b/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ()); + return $ret; } } // overridden if (preg_match('#^/a/(?P.*)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'overridden')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'overridden')), array ()); + return $ret; } if (0 === strpos($pathinfo, '/a/b\'b')) { // foo2 if (preg_match('#^/a/b\'b/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo2')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'foo2')), array ()); + return $ret; } // bar2 if (preg_match('#^/a/b\'b/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ()); + return $ret; } } @@ -155,40 +172,47 @@ public function match($pathinfo) if (0 === strpos($pathinfo, '/multi')) { // helloWorld if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P[^/]++))?$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'helloWorld')), array ( 'who' => 'World!',)); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'helloWorld')), array ( 'who' => 'World!',)); + return $ret; } // overridden2 if ($pathinfo === '/multi/new') { - return array('_route' => 'overridden2'); + $ret = array('_route' => 'overridden2'); + return $ret; } // hey if ($pathinfo === '/multi/hey/') { - return array('_route' => 'hey'); + $ret = array('_route' => 'hey'); + return $ret; } } // foo3 if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ()); + return $ret; } // bar3 if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar3')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'bar3')), array ()); + return $ret; } if (0 === strpos($pathinfo, '/aba')) { // ababa if ($pathinfo === '/ababa') { - return array('_route' => 'ababa'); + $ret = array('_route' => 'ababa'); + return $ret; } // foo4 if (preg_match('#^/aba/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ()); + return $ret; } } @@ -198,12 +222,14 @@ public function match($pathinfo) if (preg_match('#^a\\.example\\.com$#si', $host, $hostMatches)) { // route1 if ($pathinfo === '/route1') { - return array('_route' => 'route1'); + $ret = array('_route' => 'route1'); + return $ret; } // route2 if ($pathinfo === '/c2/route2') { - return array('_route' => 'route2'); + $ret = array('_route' => 'route2'); + return $ret; } } @@ -211,7 +237,8 @@ public function match($pathinfo) if (preg_match('#^b\\.example\\.com$#si', $host, $hostMatches)) { // route3 if ($pathinfo === '/c2/route3') { - return array('_route' => 'route3'); + $ret = array('_route' => 'route3'); + return $ret; } } @@ -219,7 +246,8 @@ public function match($pathinfo) if (preg_match('#^a\\.example\\.com$#si', $host, $hostMatches)) { // route4 if ($pathinfo === '/route4') { - return array('_route' => 'route4'); + $ret = array('_route' => 'route4'); + return $ret; } } @@ -227,36 +255,42 @@ public function match($pathinfo) if (preg_match('#^c\\.example\\.com$#si', $host, $hostMatches)) { // route5 if ($pathinfo === '/route5') { - return array('_route' => 'route5'); + $ret = array('_route' => 'route5'); + return $ret; } } // route6 if ($pathinfo === '/route6') { - return array('_route' => 'route6'); + $ret = array('_route' => 'route6'); + return $ret; } if (preg_match('#^(?P[^\\.]++)\\.example\\.com$#si', $host, $hostMatches)) { if (0 === strpos($pathinfo, '/route1')) { // route11 if ($pathinfo === '/route11') { - return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route11')), array ()); + $ret = $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route11')), array ()); + return $ret; } // route12 if ($pathinfo === '/route12') { - return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route12')), array ( 'var1' => 'val',)); + $ret = $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route12')), array ( 'var1' => 'val',)); + return $ret; } // route13 if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route13')), array ()); + $ret = $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route13')), array ()); + return $ret; } // route14 if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route14')), array ( 'var1' => 'val',)); + $ret = $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route14')), array ( 'var1' => 'val',)); + return $ret; } } @@ -266,7 +300,8 @@ public function match($pathinfo) if (preg_match('#^c\\.example\\.com$#si', $host, $hostMatches)) { // route15 if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ()); + return $ret; } } @@ -274,12 +309,14 @@ public function match($pathinfo) if (0 === strpos($pathinfo, '/route1')) { // route16 if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',)); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',)); + return $ret; } // route17 if ($pathinfo === '/route17') { - return array('_route' => 'route17'); + $ret = array('_route' => 'route17'); + return $ret; } } @@ -287,18 +324,21 @@ public function match($pathinfo) if (0 === strpos($pathinfo, '/a')) { // a if ($pathinfo === '/a/a...') { - return array('_route' => 'a'); + $ret = array('_route' => 'a'); + return $ret; } if (0 === strpos($pathinfo, '/a/b')) { // b if (preg_match('#^/a/b/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ()); + return $ret; } // c if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ()); + return $ret; } } 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 299e05c229a0f..dfd35e421bb72 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,8 @@ public function match($pathinfo) // foo if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?Pbaz|symfony)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',)); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',)); + return $ret; } if (0 === strpos($pathinfo, '/bar')) { @@ -38,7 +39,8 @@ public function match($pathinfo) goto not_bar; } - return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ()); + return $ret; } not_bar: @@ -49,7 +51,8 @@ public function match($pathinfo) goto not_barhead; } - return $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ()); + return $ret; } not_barhead: @@ -59,32 +62,36 @@ public function match($pathinfo) if (0 === strpos($pathinfo, '/test/baz')) { // baz if ($pathinfo === '/test/baz') { - return array('_route' => 'baz'); + $ret = array('_route' => 'baz'); + return $ret; } // baz2 if ($pathinfo === '/test/baz.html') { - return array('_route' => 'baz2'); + $ret = array('_route' => 'baz2'); + return $ret; } // baz3 if (rtrim($pathinfo, '/') === '/test/baz3') { + $ret = array('_route' => 'baz3'); if (substr($pathinfo, -1) !== '/') { - return $this->redirect($pathinfo.'/', 'baz3'); + return array_replace($ret, $this->redirect($pathinfo.'/', 'baz3')); } - return array('_route' => 'baz3'); + return $ret; } } // baz4 if (preg_match('#^/test/(?P[^/]++)/?$#s', $pathinfo, $matches)) { + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ()); if (substr($pathinfo, -1) !== '/') { - return $this->redirect($pathinfo.'/', 'baz4'); + return array_replace($ret, $this->redirect($pathinfo.'/', 'baz4')); } - return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ()); + return $ret; } // baz5 @@ -94,7 +101,8 @@ public function match($pathinfo) goto not_baz5; } - return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ()); + return $ret; } not_baz5: @@ -105,7 +113,8 @@ public function match($pathinfo) goto not_bazbaz6; } - return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ()); + return $ret; } not_bazbaz6: @@ -113,47 +122,55 @@ public function match($pathinfo) // foofoo if ($pathinfo === '/foofoo') { - return array ( 'def' => 'test', '_route' => 'foofoo',); + $ret = array ( 'def' => 'test', '_route' => 'foofoo',); + return $ret; } // quoter if (preg_match('#^/(?P[\']+)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ()); + return $ret; } // space if ($pathinfo === '/spa ce') { - return array('_route' => 'space'); + $ret = array('_route' => 'space'); + return $ret; } if (0 === strpos($pathinfo, '/a')) { if (0 === strpos($pathinfo, '/a/b\'b')) { // foo1 if (preg_match('#^/a/b\'b/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo1')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'foo1')), array ()); + return $ret; } // bar1 if (preg_match('#^/a/b\'b/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ()); + return $ret; } } // overridden if (preg_match('#^/a/(?P.*)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'overridden')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'overridden')), array ()); + return $ret; } if (0 === strpos($pathinfo, '/a/b\'b')) { // foo2 if (preg_match('#^/a/b\'b/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo2')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'foo2')), array ()); + return $ret; } // bar2 if (preg_match('#^/a/b\'b/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ()); + return $ret; } } @@ -163,44 +180,51 @@ public function match($pathinfo) if (0 === strpos($pathinfo, '/multi')) { // helloWorld if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P[^/]++))?$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'helloWorld')), array ( 'who' => 'World!',)); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'helloWorld')), array ( 'who' => 'World!',)); + return $ret; } // overridden2 if ($pathinfo === '/multi/new') { - return array('_route' => 'overridden2'); + $ret = array('_route' => 'overridden2'); + return $ret; } // hey if (rtrim($pathinfo, '/') === '/multi/hey') { + $ret = array('_route' => 'hey'); if (substr($pathinfo, -1) !== '/') { - return $this->redirect($pathinfo.'/', 'hey'); + return array_replace($ret, $this->redirect($pathinfo.'/', 'hey')); } - return array('_route' => 'hey'); + return $ret; } } // foo3 if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ()); + return $ret; } // bar3 if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar3')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'bar3')), array ()); + return $ret; } if (0 === strpos($pathinfo, '/aba')) { // ababa if ($pathinfo === '/ababa') { - return array('_route' => 'ababa'); + $ret = array('_route' => 'ababa'); + return $ret; } // foo4 if (preg_match('#^/aba/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ()); + return $ret; } } @@ -210,12 +234,14 @@ public function match($pathinfo) if (preg_match('#^a\\.example\\.com$#si', $host, $hostMatches)) { // route1 if ($pathinfo === '/route1') { - return array('_route' => 'route1'); + $ret = array('_route' => 'route1'); + return $ret; } // route2 if ($pathinfo === '/c2/route2') { - return array('_route' => 'route2'); + $ret = array('_route' => 'route2'); + return $ret; } } @@ -223,7 +249,8 @@ public function match($pathinfo) if (preg_match('#^b\\.example\\.com$#si', $host, $hostMatches)) { // route3 if ($pathinfo === '/c2/route3') { - return array('_route' => 'route3'); + $ret = array('_route' => 'route3'); + return $ret; } } @@ -231,7 +258,8 @@ public function match($pathinfo) if (preg_match('#^a\\.example\\.com$#si', $host, $hostMatches)) { // route4 if ($pathinfo === '/route4') { - return array('_route' => 'route4'); + $ret = array('_route' => 'route4'); + return $ret; } } @@ -239,36 +267,42 @@ public function match($pathinfo) if (preg_match('#^c\\.example\\.com$#si', $host, $hostMatches)) { // route5 if ($pathinfo === '/route5') { - return array('_route' => 'route5'); + $ret = array('_route' => 'route5'); + return $ret; } } // route6 if ($pathinfo === '/route6') { - return array('_route' => 'route6'); + $ret = array('_route' => 'route6'); + return $ret; } if (preg_match('#^(?P[^\\.]++)\\.example\\.com$#si', $host, $hostMatches)) { if (0 === strpos($pathinfo, '/route1')) { // route11 if ($pathinfo === '/route11') { - return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route11')), array ()); + $ret = $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route11')), array ()); + return $ret; } // route12 if ($pathinfo === '/route12') { - return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route12')), array ( 'var1' => 'val',)); + $ret = $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route12')), array ( 'var1' => 'val',)); + return $ret; } // route13 if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route13')), array ()); + $ret = $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route13')), array ()); + return $ret; } // route14 if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route14')), array ( 'var1' => 'val',)); + $ret = $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route14')), array ( 'var1' => 'val',)); + return $ret; } } @@ -278,7 +312,8 @@ public function match($pathinfo) if (preg_match('#^c\\.example\\.com$#si', $host, $hostMatches)) { // route15 if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ()); + return $ret; } } @@ -286,12 +321,14 @@ public function match($pathinfo) if (0 === strpos($pathinfo, '/route1')) { // route16 if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',)); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',)); + return $ret; } // route17 if ($pathinfo === '/route17') { - return array('_route' => 'route17'); + $ret = array('_route' => 'route17'); + return $ret; } } @@ -299,18 +336,21 @@ public function match($pathinfo) if (0 === strpos($pathinfo, '/a')) { // a if ($pathinfo === '/a/a...') { - return array('_route' => 'a'); + $ret = array('_route' => 'a'); + return $ret; } if (0 === strpos($pathinfo, '/a/b')) { // b if (preg_match('#^/a/b/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ()); + return $ret; } // c if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ()); + return $ret; } } @@ -319,20 +359,22 @@ public function match($pathinfo) // secure if ($pathinfo === '/secure') { + $ret = array('_route' => 'secure'); if ($this->context->getScheme() !== 'https') { - return $this->redirect($pathinfo, 'secure', 'https'); + return array_replace($ret, $this->redirect($pathinfo, 'secure', 'https')); } - return array('_route' => 'secure'); + return $ret; } // nonsecure if ($pathinfo === '/nonsecure') { + $ret = array('_route' => 'nonsecure'); if ($this->context->getScheme() !== 'http') { - return $this->redirect($pathinfo, 'nonsecure', 'http'); + return array_replace($ret, $this->redirect($pathinfo, 'nonsecure', 'http')); } - return array('_route' => 'nonsecure'); + return $ret; } throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException(); 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 a615ad5fd3e0f..814dab590b1e2 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher3.php @@ -28,12 +28,14 @@ public function match($pathinfo) if (0 === strpos($pathinfo, '/rootprefix')) { // static if ($pathinfo === '/rootprefix/test') { - return array('_route' => 'static'); + $ret = array('_route' => 'static'); + return $ret; } // dynamic if (preg_match('#^/rootprefix/(?P[^/]++)$#s', $pathinfo, $matches)) { - return $this->mergeDefaults(array_replace($matches, array('_route' => 'dynamic')), array ()); + $ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'dynamic')), array ()); + return $ret; } } diff --git a/src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php b/src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php index 2ad4fc8725a82..111e3e6c55e78 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php @@ -55,4 +55,19 @@ public function testSchemeRedirect() ; $matcher->match('/foo'); } + + public function testRedirectWithParams() + { + $coll = new RouteCollection(); + $coll->add('foo', new Route('/foo/{bar}', array(), array(), array(), '', array('https'))); + + $matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext())); + $matcher + ->expects($this->once()) + ->method('redirect') + ->with('/foo/baz', 'foo', 'https') + ->will($this->returnValue(array('_route' => 'foo'))) + ; + $this->assertEquals(array('_route' => 'foo', 'bar' => 'baz'), $matcher->match('/foo/baz')); + } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy