8000 bug #26318 [Routing] Fix GC control of PHP-DSL (nicolas-grekas) · symfony/symfony@1192918 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1192918

Browse files
bug #26318 [Routing] Fix GC control of PHP-DSL (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [Routing] Fix GC control of PHP-DSL | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Adding fluently in a collection is broken currently. Commits ------- 239f2e2 [Routing] Fix GC control of PHP-DSL
2 parents 68ff3d3 + 239f2e2 commit 1192918

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/Symfony/Component/Routing/Loader/Configurator/CollectionConfigurator.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ class CollectionConfigurator
2323
use Traits\RouteTrait;
2424

2525
private $parent;
26+
private $parentConfigurator;
2627

27-
public function __construct(RouteCollection $parent, $name)
28+
public function __construct(RouteCollection $parent, $name, self $parentConfigurator = null)
2829
{
2930
$this->parent = $parent;
3031
$this->name = $name;
3132
$this->collection = new RouteCollection();
3233
$this->route = new Route('');
34+
$this->parentConfigurator = $parentConfigurator; // for GC control
3335
}
3436

3537
public function __destruct()
@@ -50,7 +52,7 @@ final public function add($name, $path)
5052
{
5153
$this->collection->add($this->name.$name, $route = clone $this->route);
5254

53-
return new RouteConfigurator($this->collection, $route->setPath($path), $this->name);
55+
return new RouteConfigurator($this->collection, $route->setPath($path), $this->name, $this);
5456
}
5557

5658
/**
@@ -60,7 +62,7 @@ final public function add($name, $path)
6062
*/
6163
final public function collection($name = '')
6264
{
63-
return new self($this->collection, $this->name.$name);
65+
return new self($this->collection, $this->name.$name, $this);
6466
}
6567

6668
/**

src/Symfony/Component/Routing/Loader/Configurator/RouteConfigurator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ class RouteConfigurator
2222
use Traits\AddTrait;
2323
use Traits\RouteTrait;
2424

25-
public function __construct(RouteCollection $collection, Route $route, $name = '')
25+
private $parentConfigurator;
26+
27+
public function __construct(RouteCollection $collection, Route $route, $name = '', CollectionConfigurator $parentConfigurator = null)
2628
{
2729
$this->collection = $collection;
2830
$this->route = $route;
2931
$this->name = $name;
32+
$this->parentConfigurator = $parentConfigurator; // for GC control
3033
}
3134
}

src/Symfony/Component/Routing/Loader/Configurator/Traits/AddTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ trait AddTrait
3434
*/
3535
final public function add($name, $path)
3636
{
37+
$parentConfigurator = $this instanceof RouteConfigurator ? $this->parentConfigurator : null;
3738
$this->collection->add($this->name.$name, $route = new Route($path));
3839

39-
return new RouteConfigurator($this->collection, $route);
40+
return new RouteConfigurator($this->collection, $route, $parentConfigurator);
4041
}
4142

4243
/**

src/Symfony/Component/Routing/Tests/Fixtures/php_dsl.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
return function (RoutingConfigurator $routes) {
66
$routes
7+
->collection()
78
->add('foo', '/foo')
89
->condition('abc')
910
->options(array('utf8' => true))

0 commit comments

Comments
 (0)
0