Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/routing/RouteCollectionBuilder.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 | c2387f117808 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
36 private $options = array(); | 36 private $options = array(); |
37 private $schemes; | 37 private $schemes; |
38 private $methods; | 38 private $methods; |
39 private $resources = array(); | 39 private $resources = array(); |
40 | 40 |
41 /** | |
42 * @param LoaderInterface $loader | |
43 */ | |
44 public function __construct(LoaderInterface $loader = null) | 41 public function __construct(LoaderInterface $loader = null) |
45 { | 42 { |
46 $this->loader = $loader; | 43 $this->loader = $loader; |
47 } | 44 } |
48 | 45 |
59 * | 56 * |
60 * @throws FileLoaderLoadException | 57 * @throws FileLoaderLoadException |
61 */ | 58 */ |
62 public function import($resource, $prefix = '/', $type = null) | 59 public function import($resource, $prefix = '/', $type = null) |
63 { | 60 { |
64 /** @var RouteCollection $collection */ | 61 /** @var RouteCollection[] $collection */ |
65 $collection = $this->load($resource, $type); | 62 $collections = $this->load($resource, $type); |
66 | 63 |
67 // create a builder from the RouteCollection | 64 // create a builder from the RouteCollection |
68 $builder = $this->createBuilder(); | 65 $builder = $this->createBuilder(); |
69 foreach ($collection->all() as $name => $route) { | 66 |
70 $builder->addRoute($route, $name); | 67 foreach ($collections as $collection) { |
71 } | 68 if (null === $collection) { |
72 | 69 continue; |
73 foreach ($collection->getResources() as $resource) { | 70 } |
74 $builder->addResource($resource); | 71 |
72 foreach ($collection->all() as $name => $route) { | |
73 $builder->addRoute($route, $name); | |
74 } | |
75 | |
76 foreach ($collection->getResources() as $resource) { | |
77 $builder->addResource($resource); | |
78 } | |
75 } | 79 } |
76 | 80 |
77 // mount into this builder | 81 // mount into this builder |
78 $this->mount($prefix, $builder); | 82 $this->mount($prefix, $builder); |
79 | 83 |
199 | 203 |
200 return $this; | 204 return $this; |
201 } | 205 } |
202 | 206 |
203 /** | 207 /** |
204 * Sets an opiton that will be added to all embedded routes (unless that | 208 * Sets an option that will be added to all embedded routes (unless that |
205 * option is already set). | 209 * option is already set). |
206 * | 210 * |
207 * @param string $key | 211 * @param string $key |
208 * @param mixed $value | 212 * @param mixed $value |
209 * | 213 * |
309 $subCollection = $route->build(); | 313 $subCollection = $route->build(); |
310 $subCollection->addPrefix($this->prefix); | 314 $subCollection->addPrefix($this->prefix); |
311 | 315 |
312 $routeCollection->addCollection($subCollection); | 316 $routeCollection->addCollection($subCollection); |
313 } | 317 } |
314 | 318 } |
315 foreach ($this->resources as $resource) { | 319 |
316 $routeCollection->addResource($resource); | 320 foreach ($this->resources as $resource) { |
317 } | 321 $routeCollection->addResource($resource); |
318 } | 322 } |
319 | 323 |
320 return $routeCollection; | 324 return $routeCollection; |
321 } | 325 } |
322 | 326 |
343 * Finds a loader able to load an imported resource and loads it. | 347 * Finds a loader able to load an imported resource and loads it. |
344 * | 348 * |
345 * @param mixed $resource A resource | 349 * @param mixed $resource A resource |
346 * @param string|null $type The resource type or null if unknown | 350 * @param string|null $type The resource type or null if unknown |
347 * | 351 * |
348 * @return RouteCollection | 352 * @return RouteCollection[] |
349 * | 353 * |
350 * @throws FileLoaderLoadException If no loader is found | 354 * @throws FileLoaderLoadException If no loader is found |
351 */ | 355 */ |
352 private function load($resource, $type = null) | 356 private function load($resource, $type = null) |
353 { | 357 { |
354 if (null === $this->loader) { | 358 if (null === $this->loader) { |
355 throw new \BadMethodCallException('Cannot import other routing resources: you must pass a LoaderInterface when constructing RouteCollectionBuilder.'); | 359 throw new \BadMethodCallException('Cannot import other routing resources: you must pass a LoaderInterface when constructing RouteCollectionBuilder.'); |
356 } | 360 } |
357 | 361 |
358 if ($this->loader->supports($resource, $type)) { | 362 if ($this->loader->supports($resource, $type)) { |
359 return $this->loader->load($resource, $type); | 363 $collections = $this->loader->load($resource, $type); |
364 | |
365 return is_array($collections) ? $collections : array($collections); | |
360 } | 366 } |
361 | 367 |
362 if (null === $resolver = $this->loader->getResolver()) { | 368 if (null === $resolver = $this->loader->getResolver()) { |
363 throw new FileLoaderLoadException($resource); | 369 throw new FileLoaderLoadException($resource, null, null, null, $type); |
364 } | 370 } |
365 | 371 |
366 if (false === $loader = $resolver->resolve($resource, $type)) { | 372 if (false === $loader = $resolver->resolve($resource, $type)) { |
367 throw new FileLoaderLoadException($resource); | 373 throw new FileLoaderLoadException($resource, null, null, null, $type); |
368 } | 374 } |
369 | 375 |
370 return $loader->load($resource, $type); | 376 $collections = $loader->load($resource, $type); |
377 | |
378 return is_array($collections) ? $collections : array($collections); | |
371 } | 379 } |
372 } | 380 } |