class LazyRouteCollection

Same name in other branches
  1. 9 core/lib/Drupal/Core/Routing/LazyRouteCollection.php \Drupal\Core\Routing\LazyRouteCollection
  2. 10 core/lib/Drupal/Core/Routing/LazyRouteCollection.php \Drupal\Core\Routing\LazyRouteCollection

Hierarchy

  • class \Drupal\Core\Routing\LazyRouteCollection extends \Symfony\Component\Routing\RouteCollection

Expanded class hierarchy of LazyRouteCollection

1 file declares its use of LazyRouteCollection
LazyRouteCollectionTest.php in core/tests/Drupal/Tests/Core/Routing/LazyRouteCollectionTest.php

File

core/lib/Drupal/Core/Routing/LazyRouteCollection.php, line 9

Namespace

Drupal\Core\Routing
View source
class LazyRouteCollection extends RouteCollection {
    
    /**
     * The route provider for this generator.
     *
     * @var \Drupal\Core\Routing\RouteProviderInterface
     */
    protected $provider;
    
    /**
     * Constructs a LazyRouteCollection.
     */
    public function __construct(RouteProviderInterface $provider) {
        $this->provider = $provider;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getIterator() : \ArrayIterator {
        return new \ArrayIterator($this->all());
    }
    
    /**
     * Gets the number of Routes in this collection.
     *
     * @return int
     *   The number of routes
     */
    public function count() : int {
        return count($this->all());
    }
    
    /**
     * Returns all routes in this collection.
     *
     * @return \Symfony\Component\Routing\Route[]
     *   An array of routes
     */
    public function all() : array {
        return $this->provider
            ->getRoutesByNames(NULL);
    }
    
    /**
     * Gets a route by name.
     *
     * @param string $name
     *   The route name
     *
     * @return \Symfony\Component\Routing\Route|null
     *   A Route instance or null when not found
     */
    public function get($name) : ?Route {
        try {
            return $this->provider
                ->getRouteByName($name);
        } catch (RouteNotFoundException) {
            return NULL;
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
LazyRouteCollection::$provider protected property The route provider for this generator.
LazyRouteCollection::all public function Returns all routes in this collection.
LazyRouteCollection::count public function Gets the number of Routes in this collection.
LazyRouteCollection::get public function Gets a route by name.
LazyRouteCollection::getIterator public function
LazyRouteCollection::__construct public function Constructs a LazyRouteCollection.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.