Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= <<<EOF
if (substr(\$pathinfo, -1) !== '/') {
return \$this->redirect(\$pathinfo.'/', '$name');
return array_replace(\$ret, \$this->redirect(\$pathinfo.'/', '$name'));
}


Expand All @@ -287,30 +305,13 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren

$code .= <<<EOF
if (\$this->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) {
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Routing/Matcher/UrlMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
Loading