8000 [Routing] fixed side-effect in the PHP matcher dumper · Kiruban2011/symfony@167a96f · GitHub
[go: up one dir, main page]

Skip to content

Commit 167a96f

Browse files
committed
[Routing] fixed side-effect in the PHP matcher dumper
1 parent 08b5d73 commit 167a96f

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public function dump(array $options = array())
5454

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

5960
return <<<EOF
6061
@@ -74,7 +75,6 @@ private function compileRoutes(RouteCollection $routes, $supportsRedirections, $
7475
{
7576
$code = array();
7677

77-
$routes = clone $routes;
7878
$routeIterator = $routes->getIterator();
7979
$keys = array_keys($routeIterator->getArrayCopy());
8080
$keysCount = count($keys);
@@ -83,7 +83,6 @@ private function compileRoutes(RouteCollection $routes, $supportsRedirections, $
8383
foreach ($routeIterator as $name => $route) {
8484
$i++;
8585

86-
$route = clone $route;
8786
if ($route instanceof RouteCollection) {
8887
$prefix = $route->getPrefix();
8988
$optimizable = $prefix && count($route->all()) > 1 && false === strpos($route->getPrefix(), '{');

src/Symfony/Component/Routing/Route.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public function __construct($pattern, array $defaults = array(), array $requirem
5050
$this->setOptions($options);
5151
}
5252

53+
public function __clone()
54+
{
55+
$this->compiled = null;
56+
}
57+
5358
/**
5459
* Returns the pattern.
5560
*

src/Symfony/Component/Routing/RouteCollection.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ public function __construct()
4242
$this->prefix = '';
4343
}
4444

45+
public function __clone()
46+
{
47+
$parent = $this;
48+
foreach ($this->routes as $name => $route) {
49+
$this->routes[$name] = clone $route;
50+
if ($route instanceof RouteCollection) {
51+
$this->routes[$name]->setParent($this);
52+
}
53+
}
54+
}
55+
4556
/**
4657
* Gets the parent RouteCollection.
4758
*

0 commit comments

Comments
 (0)
0