Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony-cmf/routing/LazyRouteCollection.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of the Symfony CMF package. | |
5 * | |
6 * (c) 2011-2015 Symfony CMF | |
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\Cmf\Component\Routing; | |
13 | |
14 use Symfony\Component\Routing\Exception\RouteNotFoundException; | |
15 use Symfony\Component\Routing\RouteCollection; | |
16 use Symfony\Component\Routing\Route; | |
17 | |
18 class LazyRouteCollection extends RouteCollection | |
19 { | |
20 /** | |
21 * The route provider for this generator. | |
22 * | |
23 * @var RouteProviderInterface | |
24 */ | |
25 protected $provider; | |
26 | |
27 public function __construct(RouteProviderInterface $provider) | |
28 { | |
29 $this->provider = $provider; | |
30 } | |
31 | |
32 /** | |
33 * {@inheritdoc} | |
34 */ | |
35 public function getIterator() | |
36 { | |
37 return new \ArrayIterator($this->all()); | |
38 } | |
39 | |
40 /** | |
41 * Gets the number of Routes in this collection. | |
42 * | |
43 * @return int The number of routes | |
44 */ | |
45 public function count() | |
46 { | |
47 return count($this->all()); | |
48 } | |
49 | |
50 /** | |
51 * Returns all routes in this collection. | |
52 * | |
53 * @return Route[] An array of routes | |
54 */ | |
55 public function all() | |
56 { | |
57 return $this->provider->getRoutesByNames(null); | |
58 } | |
59 | |
60 /** | |
61 * Gets a route by name. | |
62 * | |
63 * @param string $name The route name | |
64 * | |
65 * @return Route|null A Route instance or null when not found | |
66 */ | |
67 public function get($name) | |
68 { | |
69 try { | |
70 return $this->provider->getRouteByName($name); | |
71 } catch (RouteNotFoundException $e) { | |
72 return; | |
73 } | |
74 } | |
75 } |