4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Routing\Loader\Configurator;
14 use Symfony\Component\Routing\Route;
15 use Symfony\Component\Routing\RouteCollection;
18 * @author Nicolas Grekas <p@tchwork.com>
20 class CollectionConfigurator
23 use Traits\RouteTrait;
26 private $parentConfigurator;
28 public function __construct(RouteCollection $parent, $name, self $parentConfigurator = null)
30 $this->parent = $parent;
32 $this->collection = new RouteCollection();
33 $this->route = new Route('');
34 $this->parentConfigurator = $parentConfigurator; // for GC control
37 public function __destruct()
39 $this->collection->addPrefix(rtrim($this->route->getPath(), '/'));
40 $this->parent->addCollection($this->collection);
49 * @return RouteConfigurator
51 final public function add($name, $path)
53 $this->collection->add($this->name.$name, $route = clone $this->route);
55 return new RouteConfigurator($this->collection, $route->setPath($path), $this->name, $this);
59 * Creates a sub-collection.
63 final public function collection($name = '')
65 return new self($this->collection, $this->name.$name, $this);
69 * Sets the prefix to add to the path of all child routes.
71 * @param string $prefix
75 final public function prefix($prefix)
77 $this->route->setPath($prefix);