comparison vendor/symfony/routing/RouteCollection.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 4c8ae668cc8c
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
102 } 102 }
103 103
104 /** 104 /**
105 * Removes a route or an array of routes by name from the collection. 105 * Removes a route or an array of routes by name from the collection.
106 * 106 *
107 * @param string|array $name The route name or an array of route names 107 * @param string|string[] $name The route name or an array of route names
108 */ 108 */
109 public function remove($name) 109 public function remove($name)
110 { 110 {
111 foreach ((array) $name as $n) { 111 foreach ((array) $name as $n) {
112 unset($this->routes[$n]); 112 unset($this->routes[$n]);
114 } 114 }
115 115
116 /** 116 /**
117 * Adds a route collection at the end of the current set by appending all 117 * Adds a route collection at the end of the current set by appending all
118 * routes of the added collection. 118 * routes of the added collection.
119 * 119 */
120 * @param RouteCollection $collection A RouteCollection instance 120 public function addCollection(self $collection)
121 */
122 public function addCollection(RouteCollection $collection)
123 { 121 {
124 // we need to remove all routes with the same names first because just replacing them 122 // 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 123 // would not place the new route at the end of the merged array
126 foreach ($collection->all() as $name => $route) { 124 foreach ($collection->all() as $name => $route) {
127 unset($this->routes[$name]); 125 unset($this->routes[$name]);
128 $this->routes[$name] = $route; 126 $this->routes[$name] = $route;
129 } 127 }
130 128
131 $this->resources = array_merge($this->resources, $collection->getResources()); 129 foreach ($collection->getResources() as $resource) {
130 $this->addResource($resource);
131 }
132 } 132 }
133 133
134 /** 134 /**
135 * Adds a prefix to the path of all child routes. 135 * Adds a prefix to the path of all child routes.
136 * 136 *
232 } 232 }
233 233
234 /** 234 /**
235 * Sets the schemes (e.g. 'https') all child routes are restricted to. 235 * Sets the schemes (e.g. 'https') all child routes are restricted to.
236 * 236 *
237 * @param string|array $schemes The scheme or an array of schemes 237 * @param string|string[] $schemes The scheme or an array of schemes
238 */ 238 */
239 public function setSchemes($schemes) 239 public function setSchemes($schemes)
240 { 240 {
241 foreach ($this->routes as $route) { 241 foreach ($this->routes as $route) {
242 $route->setSchemes($schemes); 242 $route->setSchemes($schemes);
244 } 244 }
245 245
246 /** 246 /**
247 * Sets the HTTP methods (e.g. 'POST') all child routes are restricted to. 247 * Sets the HTTP methods (e.g. 'POST') all child routes are restricted to.
248 * 248 *
249 * @param string|array $methods The method or an array of methods 249 * @param string|string[] $methods The method or an array of methods
250 */ 250 */
251 public function setMethods($methods) 251 public function setMethods($methods)
252 { 252 {
253 foreach ($this->routes as $route) { 253 foreach ($this->routes as $route) {
254 $route->setMethods($methods); 254 $route->setMethods($methods);
260 * 260 *
261 * @return ResourceInterface[] An array of resources 261 * @return ResourceInterface[] An array of resources
262 */ 262 */
263 public function getResources() 263 public function getResources()
264 { 264 {
265 return array_unique($this->resources); 265 return array_values($this->resources);
266 } 266 }
267 267
268 /** 268 /**
269 * Adds a resource for this collection. 269 * Adds a resource for this collection. If the resource already exists
270 * 270 * it is not added.
271 * @param ResourceInterface $resource A resource instance
272 */ 271 */
273 public function addResource(ResourceInterface $resource) 272 public function addResource(ResourceInterface $resource)
274 { 273 {
275 $this->resources[] = $resource; 274 $key = (string) $resource;
275
276 if (!isset($this->resources[$key])) {
277 $this->resources[$key] = $resource;
278 }
276 } 279 }
277 } 280 }