4 * This file is part of the Symfony CMF package.
6 * (c) 2011-2015 Symfony CMF
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Cmf\Component\Routing;
14 use Symfony\Component\Routing\Exception\RouteNotFoundException;
15 use Symfony\Component\Routing\RouteCollection;
16 use Symfony\Component\Routing\Route;
18 class LazyRouteCollection extends RouteCollection
21 * The route provider for this generator.
23 * @var RouteProviderInterface
27 public function __construct(RouteProviderInterface $provider)
29 $this->provider = $provider;
35 public function getIterator()
37 return new \ArrayIterator($this->all());
41 * Gets the number of Routes in this collection.
43 * @return int The number of routes
45 public function count()
47 return count($this->all());
51 * Returns all routes in this collection.
53 * @return Route[] An array of routes
57 return $this->provider->getRoutesByNames(null);
61 * Gets a route by name.
63 * @param string $name The route name
65 * @return Route|null A Route instance or null when not found
67 public function get($name)
70 return $this->provider->getRouteByName($name);
71 } catch (RouteNotFoundException $e) {