Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
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 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