Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Routing] fixed side-effect in the PHP matcher dumper
  • Loading branch information
fabpot committed Oct 24, 2011
1 parent 76148d0 commit cbb4bba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Expand Up @@ -54,7 +54,8 @@ public function dump(array $options = array())

private function addMatcher($supportsRedirections)
{
$code = implode("\n", $this->compileRoutes($this->getRoutes(), $supportsRedirections));
// we need to deep clone the routes as we will modify the structure to optimize the dump
$code = implode("\n", $this->compileRoutes(clone $this->getRoutes(), $supportsRedirections));

return <<<EOF
Expand All @@ -74,7 +75,6 @@ private function compileRoutes(RouteCollection $routes, $supportsRedirections, $
{
$code = array();

$routes = clone $routes;
$routeIterator = $routes->getIterator();
$keys = array_keys($routeIterator->getArrayCopy());
$keysCount = count($keys);
Expand All @@ -83,7 +83,6 @@ private function compileRoutes(RouteCollection $routes, $supportsRedirections, $
foreach ($routeIterator as $name => $route) {
$i++;

$route = clone $route;
if ($route instanceof RouteCollection) {
$prefix = $route->getPrefix();
$optimizable = $prefix && count($route->all()) > 1 && false === strpos($route->getPrefix(), '{');
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Routing/Route.php
Expand Up @@ -50,6 +50,11 @@ public function __construct($pattern, array $defaults = array(), array $requirem
$this->setOptions($options);
}

public function __clone()
{
$this->compiled = null;
}

/**
* Returns the pattern.
*
Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/Routing/RouteCollection.php
Expand Up @@ -42,6 +42,17 @@ public function __construct()
$this->prefix = '';
}

public function __clone()
{
$parent = $this;
foreach ($this->routes as $name => $route) {
$this->routes[$name] = clone $route;
if ($route instanceof RouteCollection) {
$this->routes[$name]->setParent($this);
}
}
}

/**
* Gets the parent RouteCollection.
*
Expand Down

0 comments on commit cbb4bba

Please sign in to comment.