8000 [Routing] removed tree structure from RouteCollection by Tobion · Pull Request #6120 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Routing] removed tree structure from RouteCollection #6120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 6, 2012
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[Routing] removed tree structure from RouteCollection
  • Loading branch information
Tobion committed Nov 26, 2012
commit 98f3ca83959e71f91e54315d7f50923a86ba3a45
20 changes: 8 additions & 12 deletions src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,15 @@ public function warmUp($cacheDir)
private function resolveParameters(RouteCollection $collection)
{
foreach ($collection as $route) {
if ($route instanceof RouteCollection) {
$this->resolveParameters($route);
} else {
foreach ($route->getDefaults() as $name => $value) {
$route->setDefault($name, $this->resolve($value));
}

foreach ($route->getRequirements() as $name => $value) {
$route->setRequirement($name, $this->resolve($value));
}

$route->setPattern($this->resolve($route->getPattern()));
foreach ($route->getDefaults() as $name => $value) {
$route->setDefault($name, $this->resolve($value));
}

foreach ($route->getRequirements() as $name => $value) {
$route->setRequirement($name, $this->resolve($value));
}

$route->setPattern($this->resolve($route->getPattern()));
}
}

Expand Down
34 changes: 4 additions & 30 deletions src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php
Original file line number Diff line number Diff line c 8000 hange
Expand Up @@ -111,7 +111,6 @@ private function compileRoutes(RouteCollection $routes, $supportsRedirections)
{
$fetchedHostname = false;

$routes = $this->flattenRouteCollection($routes);
$groups = $this->groupRoutesByHostnameRegex($routes);
$code = '';

Expand Down Expand Up @@ -321,31 +320,6 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
return $code;
}

/**
* Flattens a tree of routes to a single collection.
*
* @param RouteCollection $routes Collection of routes
* @param DumperCollection|null $to A DumperCollection to add routes to
*
* @return DumperCollection
*/
private function flattenRouteCollection(RouteCollection $routes, DumperCollection $to = null)
{
if (null === $to) {
$to = new DumperCollection();
}

foreach ($routes as $name => $route) {
if ($route instanceof RouteCollection) {
$this->flattenRouteCollection($route, $to);
} else {
$to->add(new DumperRoute($name, $route));
}
}

return $to;
}

/**
* Groups consecutive routes having the same hostname regex.
*
Expand All @@ -355,22 +329,22 @@ private function flattenRouteCollection(RouteCollection $routes, DumperCollectio
*
* @return DumperCollection A collection with routes grouped by hostname regex in sub-collections
*/
private function groupRoutesByHostnameRegex(DumperCollection $routes)
private function groupRoutesByHostnameRegex(RouteCollection $routes)
{
$groups = new DumperCollection();

$currentGroup = new DumperCollection();
$currentGroup->setAttribute('hostname_regex', null);
$groups->add($currentGroup);

foreach ($routes as $route) {
$hostnameRegex = $route->getRoute()->compile()->getHostnameRegex();
foreach ($routes as $name => $route) {
$hostnameRegex = $route->compile()->getHostnameRegex();
if ($currentGroup->getAttribute('hostname_regex') !== $hostnameRegex) {
$currentGroup = new DumperCollection();
$currentGroup->setAttribute('hostname_regex', $hostnameRegex);
$groups->add($currentGroup);
}
$currentGroup->add($route);
$currentGroup->add(new DumperRoute($name, $route));
}

return $groups;
Expand Down
8 changes: 0 additions & 8 deletions src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ public function getTraces($pathinfo)
protected function matchCollection($pathinfo, RouteCollection $routes)
{
foreach ($routes as $name => $route) {
if ($route instanceof RouteCollection) {
if (!$ret = $this->matchCollection($pathinfo, $route)) {
continue;
}

return true;
}

$compiledRoute = $route->compile();

if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
Expand Down
12 changes: 0 additions & 12 deletions src/Symfony/Component/Routing/Matcher/UrlMatcher.php
< 5993 td id="diff-a887ff1cedb156594d5b2e9c27ae5c1c66915795cca7ccd9b7eac026bf80f121L117" data-line-number="117" class="blob-num blob-num-deletion js-linkable-line-number">
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,6 @@ public function match($pathinfo)
protected function matchCollection($pathinfo, RouteCollection $routes)
{
foreach ($routes as $name => $route) {
if ($route instanceof RouteCollection) {
if (false === strpos($route->getPrefix(), '{') && $route->getPrefix() !== substr($pathinfo, 0, strlen($route->getPrefix()))) {
continue;
}

if (!$ret = $this->matchCollection($pathinfo, $route)) {
continue;
}

return $ret;
}

$compiledRoute = $route->compile();

// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
Expand Down
Loading
0