Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
RouteCollection.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\Routing;
013
014 use Symfony\Component\Config\Resource\ResourceInterface;
015
016 /**
017 * A RouteCollection represents a set of Route instances.
018 *
019 * When adding a route at the end of the collection, an existing route
020 * with the same name is removed first. So there can only be one route
021 * with a given name.
022 *
023 * @author Fabien Potencier <fabien@symfony.com>
024 * @author Tobias Schultze <http://tobion.de>
025 */
026 class RouteCollection implements \IteratorAggregate, \Countable
027 {
028 /**
029 * @var Route[]
030 */
031 private $routes = array();
032
033 /**
034 * @var array
035 */
036 private $resources = array();
037
038 public function __clone()
039 {
040 foreach ($this->routes as $name => $route) {
041 $this->routes[$name] = clone $route;
042 }
043 }
044
045 /**
046 * Gets the current RouteCollection as an Iterator that includes all routes.
047 *
048 * It implements \IteratorAggregate.
049 *
050 * @see all()
051 *
052 * @return \ArrayIterator|Route[] An \ArrayIterator object for iterating over routes
053 */
054 public function getIterator()
055 {
056 return new \ArrayIterator($this->routes);
057 }
058
059 /**
060 * Gets the number of Routes in this collection.
061 *
062 * @return int The number of routes
063 */
064 public function count()
065 {
066 return count($this->routes);
067 }
068
069 /**
070 * Adds a route.
071 *
072 * @param string $name The route name
073 * @param Route $route A Route instance
074 */
075 public function add($name, Route $route)
076 {
077 unset($this->routes[$name]);
078
079 $this->routes[$name] = $route;
080 }
081
082 /**
083 * Returns all routes in this collection.
084 *
085 * @return Route[] An array of routes
086 */
087 public function all()
088 {
089 return $this->routes;
090 }
091
092 /**
093 * Gets a route by name.
094 *
095 * @param string $name The route name
096 *
097 * @return Route|null A Route instance or null when not found
098 */
099 public function get($name)
100 {
101 return isset($this->routes[$name]) ? $this->routes[$name] : null;
102 }
103
104 /**
105 * Removes a route or an array of routes by name from the collection.
106 *
107 * @param string|array $name The route name or an array of route names
108 */
109 public function remove($name)
110 {
111 foreach ((array) $name as $n) {
112 unset($this->routes[$n]);
113 }
114 }
115
116 /**
117 * Adds a route collection at the end of the current set by appending all
118 * routes of the added collection.
119 *
120 * @param RouteCollection $collection A RouteCollection instance
121 */
122 public function addCollection(RouteCollection $collection)
123 {
124 // we need to remove all routes with the same names first because just replacing them
125 // would not place the new route at the end of the merged array
126 foreach ($collection->all() as $name => $route) {
127 unset($this->routes[$name]);
128 $this->routes[$name] = $route;
129 }
130
131 $this->resources = array_merge($this->resources, $collection->getResources());
132 }
133
134 /**
135 * Adds a prefix to the path of all child routes.
136 *
137 * @param string $prefix An optional prefix to add before each pattern of the route collection
138 * @param array $defaults An array of default values
139 * @param array $requirements An array of requirements
140 */
141 public function addPrefix($prefix, array $defaults = array(), array $requirements = array())
142 {
143 $prefix = trim(trim($prefix), '/');
144
145 if ('' === $prefix) {
146 return;
147 }
148
149 foreach ($this->routes as $route) {
150 $route->setPath('/'.$prefix.$route->getPath());
151 $route->addDefaults($defaults);
152 $route->addRequirements($requirements);
153 }
154 }
155
156 /**
157 * Sets the host pattern on all routes.
158 *
159 * @param string $pattern The pattern
160 * @param array $defaults An array of default values
161 * @param array $requirements An array of requirements
162 */
163 public function setHost($pattern, array $defaults = array(), array $requirements = array())
164 {
165 foreach ($this->routes as $route) {
166 $route->setHost($pattern);
167 $route->addDefaults($defaults);
168 $route->addRequirements($requirements);
169 }
170 }
171
172 /**
173 * Sets a condition on all routes.
174 *
175 * Existing conditions will be overridden.
176 *
177 * @param string $condition The condition
178 */
179 public function setCondition($condition)
180 {
181 foreach ($this->routes as $route) {
182 $route->setCondition($condition);
183 }
184 }
185
186 /**
187 * Adds defaults to all routes.
188 *
189 * An existing default value under the same name in a route will be overridden.
190 *
191 * @param array $defaults An array of default values
192 */
193 public function addDefaults(array $defaults)
194 {
195 if ($defaults) {
196 foreach ($this->routes as $route) {
197 $route->addDefaults($defaults);
198 }
199 }
200 }
201
202 /**
203 * Adds requirements to all routes.
204 *
205 * An existing requirement under the same name in a route will be overridden.
206 *
207 * @param array $requirements An array of requirements
208 */
209 public function addRequirements(array $requirements)
210 {
211 if ($requirements) {
212 foreach ($this->routes as $route) {
213 $route->addRequirements($requirements);
214 }
215 }
216 }
217
218 /**
219 * Adds options to all routes.
220 *
221 * An existing option value under the same name in a route will be overridden.
222 *
223 * @param array $options An array of options
224 */
225 public function addOptions(array $options)
226 {
227 if ($options) {
228 foreach ($this->routes as $route) {
229 $route->addOptions($options);
230 }
231 }
232 }
233
234 /**
235 * Sets the schemes (e.g. 'https') all child routes are restricted to.
236 *
237 * @param string|array $schemes The scheme or an array of schemes
238 */
239 public function setSchemes($schemes)
240 {
241 foreach ($this->routes as $route) {
242 $route->setSchemes($schemes);
243 }
244 }
245
246 /**
247 * Sets the HTTP methods (e.g. 'POST') all child routes are restricted to.
248 *
249 * @param string|array $methods The method or an array of methods
250 */
251 public function setMethods($methods)
252 {
253 foreach ($this->routes as $route) {
254 $route->setMethods($methods);
255 }
256 }
257
258 /**
259 * Returns an array of resources loaded to build this collection.
260 *
261 * @return ResourceInterface[] An array of resources
262 */
263 public function getResources()
264 {
265 return array_unique($this->resources);
266 }
267
268 /**
269 * Adds a resource for this collection.
270 *
271 * @param ResourceInterface $resource A resource instance
272 */
273 public function addResource(ResourceInterface $resource)
274 {
275 $this->resources[] = $resource;
276 }
277 }
278