You are here

class PagedRouteCollection in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony-cmf/routing/PagedRouteCollection.php \Symfony\Cmf\Component\Routing\PagedRouteCollection

Provides a route collection which avoids having all routes in memory.

Internally, this does load multiple routes over time using a PagedRouteProviderInterface $route_provider.

Hierarchy

  • class \Symfony\Cmf\Component\Routing\PagedRouteCollection implements \Symfony\Cmf\Component\Routing\Iterator, \Symfony\Cmf\Component\Routing\Countable

Expanded class hierarchy of PagedRouteCollection

1 file declares its use of PagedRouteCollection
RouteProvider.php in core/lib/Drupal/Core/Routing/RouteProvider.php
Contains \Drupal\Core\Routing\RouteProvider.

File

vendor/symfony-cmf/routing/PagedRouteCollection.php, line 20

Namespace

Symfony\Cmf\Component\Routing
View source
class PagedRouteCollection implements \Iterator, \Countable {

  /**
   * @var PagedRouteProviderInterface
   */
  protected $provider;

  /**
   * Stores the amount of routes which are loaded in parallel and kept in
   * memory.
   *
   * @var int
   */
  protected $routesBatchSize;

  /**
   * Contains the current item the iterator points to.
   *
   * @var int
   */
  protected $current = -1;

  /**
   * Stores the current loaded routes.
   *
   * @var \Symfony\Component\Routing\Route[]
   */
  protected $currentRoutes;
  public function __construct(PagedRouteProviderInterface $pagedRouteProvider, $routesBatchSize = 50) {
    $this->provider = $pagedRouteProvider;
    $this->routesBatchSize = $routesBatchSize;
  }

  /**
   * Loads the next routes into the elements array.
   *
   * @param int $offset The offset used in the db query.
   */
  protected function loadNextElements($offset) {

    // If the last batch was smaller than the batch size, this means there
    // are no more routes available.
    if (isset($this->currentRoutes) && count($this->currentRoutes) < $this->routesBatchSize) {
      $this->currentRoutes = array();
    }
    else {
      $this->currentRoutes = $this->provider
        ->getRoutesPaged($offset, $this->routesBatchSize);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function current() {
    return current($this->currentRoutes);
  }

  /**
   * {@inheritdoc}
   */
  public function next() {
    $result = next($this->currentRoutes);
    if (false === $result) {
      $this
        ->loadNextElements($this->current + 1);
    }
    $this->current++;
  }

  /**
   * {@inheritdoc}
   */
  public function key() {
    return key($this->currentRoutes);
  }

  /**
   * {@inheritdoc}
   */
  public function valid() {
    return key($this->currentRoutes);
  }

  /**
   * {@inheritdoc}
   */
  public function rewind() {
    $this->current = 0;
    $this->currentRoutes = NULL;
    $this
      ->loadNextElements($this->current);
  }

  /**
   * Gets the number of Routes in this collection.
   *
   * @return int The number of routes
   */
  public function count() {
    return $this->provider
      ->getRoutesCount();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PagedRouteCollection::$current protected property Contains the current item the iterator points to.
PagedRouteCollection::$currentRoutes protected property Stores the current loaded routes.
PagedRouteCollection::$provider protected property
PagedRouteCollection::$routesBatchSize protected property Stores the amount of routes which are loaded in parallel and kept in memory.
PagedRouteCollection::count public function Gets the number of Routes in this collection.
PagedRouteCollection::current public function
PagedRouteCollection::key public function
PagedRouteCollection::loadNextElements protected function Loads the next routes into the elements array.
PagedRouteCollection::next public function
PagedRouteCollection::rewind public function
PagedRouteCollection::valid public function
PagedRouteCollection::__construct public function