Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace Symfony\Component\Routing\Loader\Configurator; Chris@14: Chris@14: use Symfony\Component\Routing\Route; Chris@14: use Symfony\Component\Routing\RouteCollection; Chris@14: Chris@14: /** Chris@14: * @author Nicolas Grekas Chris@14: */ Chris@14: class CollectionConfigurator Chris@14: { Chris@14: use Traits\AddTrait; Chris@14: use Traits\RouteTrait; Chris@14: Chris@14: private $parent; Chris@14: private $parentConfigurator; Chris@14: Chris@14: public function __construct(RouteCollection $parent, $name, self $parentConfigurator = null) Chris@14: { Chris@14: $this->parent = $parent; Chris@14: $this->name = $name; Chris@14: $this->collection = new RouteCollection(); Chris@14: $this->route = new Route(''); Chris@14: $this->parentConfigurator = $parentConfigurator; // for GC control Chris@14: } Chris@14: Chris@14: public function __destruct() Chris@14: { Chris@14: $this->collection->addPrefix(rtrim($this->route->getPath(), '/')); Chris@14: $this->parent->addCollection($this->collection); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Adds a route. Chris@14: * Chris@14: * @param string $name Chris@14: * @param string $path Chris@14: * Chris@14: * @return RouteConfigurator Chris@14: */ Chris@14: final public function add($name, $path) Chris@14: { Chris@14: $this->collection->add($this->name.$name, $route = clone $this->route); Chris@14: Chris@14: return new RouteConfigurator($this->collection, $route->setPath($path), $this->name, $this); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Creates a sub-collection. Chris@14: * Chris@14: * @return self Chris@14: */ Chris@14: final public function collection($name = '') Chris@14: { Chris@14: return new self($this->collection, $this->name.$name, $this); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Sets the prefix to add to the path of all child routes. Chris@14: * Chris@14: * @param string $prefix Chris@14: * Chris@14: * @return $this Chris@14: */ Chris@14: final public function prefix($prefix) Chris@14: { Chris@14: $this->route->setPath($prefix); Chris@14: Chris@14: return $this; Chris@14: } Chris@14: }