diff --git a/src/Symfony/Component/Routing/Loader/Configurator/CollectionConfigurator.php b/src/Symfony/Component/Routing/Loader/Configurator/CollectionConfigurator.php index 38d86cb895cb4..8baefdd592745 100644 --- a/src/Symfony/Component/Routing/Loader/Configurator/CollectionConfigurator.php +++ b/src/Symfony/Component/Routing/Loader/Configurator/CollectionConfigurator.php @@ -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() @@ -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); } /** @@ -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); } /** diff --git a/src/Symfony/Component/Routing/Loader/Configurator/RouteConfigurator.php b/src/Symfony/Component/Routing/Loader/Configurator/RouteConfigurator.php index b8d87025435e0..6422bbf6768f3 100644 --- a/src/Symfony/Component/Routing/Loader/Configurator/RouteConfigurator.php +++ b/src/Symfony/Component/Routing/Loader/Configurator/RouteConfigurator.php @@ -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 } } diff --git a/src/Symfony/Component/Routing/Loader/Configurator/Traits/AddTrait.php b/src/Symfony/Component/Routing/Loader/Configurator/Traits/AddTrait.php index 7171fd241f6d0..01a082aed3220 100644 --- a/src/Symfony/Component/Routing/Loader/Configurator/Traits/AddTrait.php +++ b/src/Symfony/Component/Routing/Loader/Configurator/Traits/AddTrait.php @@ -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); } /** diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/php_dsl.php b/src/Symfony/Component/Routing/Tests/Fixtures/php_dsl.php index 04f6d7ed6eab2..0780c9fa80f1d 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/php_dsl.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/php_dsl.php @@ -4,6 +4,7 @@ return function (RoutingConfigurator $routes) { $routes + ->collection() ->add('foo', '/foo') ->condition('abc') ->options(array('utf8' => true))