Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Routing] Fix GC control of PHP-DSL #26318

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 1 commit into from
Feb 26, 2018
Merged
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
[Routing] Fix GC control of PHP-DSL
  • Loading branch information
nicolas-grekas committed Feb 26, 2018
commit 239f2e21e554feb0a02c615b6da48272879d844a
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ class CollectionConfigurator
use Traits\RouteTrait;

private $parent;
private $parentConfigurator;

public function __construct(RouteCollection $parent, $name)
public function __construct(RouteCollection $parent, $name, self $parentConfigurator = null)
{
$this->parent = $parent;
$this->name = $name;
$this->collection = new RouteCollection();
$this->route = new Route('');
$this->parentConfigurator = $parentConfigurator; // for GC control
}

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

return new RouteConfigurator($this->collection, $route->setPath($path), $this->name);
return new RouteConfigurator($this->collection, $route->setPath($path), $this->name, $this);
}

/**
Expand All @@ -60,7 +62,7 @@ final public function add($name, $path)
*/
final public function collection($name = '')
{
return new self($this->collection, $this->name.$name);
return new self($this->collection, $this->name.$name, $this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ class RouteConfigurator
use Traits\AddTrait;
use Traits\RouteTrait;

public function __construct(RouteCollection $collection, Route $route, $name = '')
private $parentConfigurator;

public function __construct(RouteCollection $collection, Route $route, $name = '', CollectionConfigurator $parentConfigurator = null)
{
$this->collection = $collection;
$this->route = $route;
$this->name = $name;
$this->parentConfigurator = $parentConfigurator; // for GC control
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ trait AddTrait
*/
final public function add($name, $path)
{
$parentConfigurator = $this instanceof RouteConfigurator ? $this->parentConfigurator : null;
$this->collection->add($this->name.$name, $route = new Route($path));

return new RouteConfigurator($this->collection, $route);
return new RouteConfigurator($this->collection, $route, $parentConfigurator);
}

/**
Expand Down
1 change: 1 addition & 0 deletions 1 src/Symfony/Component/Routing/Tests/Fixtures/php_dsl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

return function (RoutingConfigurator $routes) {
$routes
->collection()
->add('foo', '/foo')
->condition('abc')
->options(array('utf8' => true))
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.