Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/routing/Loader/Configurator/CollectionConfigurator.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of the Symfony package. | |
5 * | |
6 * (c) Fabien Potencier <fabien@symfony.com> | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Symfony\Component\Routing\Loader\Configurator; | |
13 | |
14 use Symfony\Component\Routing\Route; | |
15 use Symfony\Component\Routing\RouteCollection; | |
16 | |
17 /** | |
18 * @author Nicolas Grekas <p@tchwork.com> | |
19 */ | |
20 class CollectionConfigurator | |
21 { | |
22 use Traits\AddTrait; | |
23 use Traits\RouteTrait; | |
24 | |
25 private $parent; | |
26 private $parentConfigurator; | |
27 | |
28 public function __construct(RouteCollection $parent, $name, self $parentConfigurator = null) | |
29 { | |
30 $this->parent = $parent; | |
31 $this->name = $name; | |
32 $this->collection = new RouteCollection(); | |
33 $this->route = new Route(''); | |
34 $this->parentConfigurator = $parentConfigurator; // for GC control | |
35 } | |
36 | |
37 public function __destruct() | |
38 { | |
39 $this->collection->addPrefix(rtrim($this->route->getPath(), '/')); | |
40 $this->parent->addCollection($this->collection); | |
41 } | |
42 | |
43 /** | |
44 * Adds a route. | |
45 * | |
46 * @param string $name | |
47 * @param string $path | |
48 * | |
49 * @return RouteConfigurator | |
50 */ | |
51 final public function add($name, $path) | |
52 { | |
53 $this->collection->add($this->name.$name, $route = clone $this->route); | |
54 | |
55 return new RouteConfigurator($this->collection, $route->setPath($path), $this->name, $this); | |
56 } | |
57 | |
58 /** | |
59 * Creates a sub-collection. | |
60 * | |
61 * @return self | |
62 */ | |
63 final public function collection($name = '') | |
64 { | |
65 return new self($this->collection, $this->name.$name, $this); | |
66 } | |
67 | |
68 /** | |
69 * Sets the prefix to add to the path of all child routes. | |
70 * | |
71 * @param string $prefix | |
72 * | |
73 * @return $this | |
74 */ | |
75 final public function prefix($prefix) | |
76 { | |
77 $this->route->setPath($prefix); | |
78 | |
79 return $this; | |
80 } | |
81 } |