Skip to content

Commit

Permalink
[Routing] fixed route matching when the prefix contains variables
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 4, 2011
1 parent 6e95621 commit 95a267b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Matcher/Dumper/PhpMatcherDumper.php
Expand Up @@ -74,8 +74,10 @@ private function compileRoutes(RouteCollection $routes, $supportsRedirections)
$code = array();
foreach ($routes as $name => $route) {
if ($route instanceof RouteCollection) {
$prefix = $route->getPrefix();
$optimizable = $prefix && count($route->all()) > 1 && false === strpos($route->getPrefix(), '{');
$indent = '';
if (count($route->all()) > 1 && $prefix = $route->getPrefix()) {
if ($optimizable) {
$code[] = sprintf(" if (0 === strpos(\$pathinfo, '%s')) {", $prefix);
$indent = ' ';
}
Expand All @@ -86,7 +88,7 @@ private function compileRoutes(RouteCollection $routes, $supportsRedirections)
}
}

if ($indent) {
if ($optimizable) {
$code[] = " }\n";
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion Matcher/UrlMatcher.php
Expand Up @@ -87,7 +87,7 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
{
foreach ($routes as $name => $route) {
if ($route instanceof RouteCollection) {
if ($route->getPrefix() !== substr($pathinfo, 0, strlen($route->getPrefix()))) {
if (false === strpos($route->getPrefix(), '{') && $route->getPrefix() !== substr($pathinfo, 0, strlen($route->getPrefix()))) {
continue;
}

Expand Down

0 comments on commit 95a267b

Please sign in to comment.