You are here

public function LazyRouteFilter::filter in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Routing/LazyRouteFilter.php \Drupal\Core\Routing\LazyRouteFilter::filter()

Filters the route collection against a request and returns all matching routes.

Parameters

RouteCollection $collection The collection against which to match.:

Request $request A Request object against which to match.:

Return value

RouteCollection A non-empty RouteCollection of matched routes.

Throws

ResourceNotFoundException if none of the routes in $collection matches $request. This is a performance optimization to not continue the match process when a match will no longer be possible.

Overrides RouteFilterInterface::filter

File

core/lib/Drupal/Core/Routing/LazyRouteFilter.php, line 90
Contains \Drupal\Core\Routing\LazyRouteFilter.

Class

LazyRouteFilter
A route filter which lazily loads route filters, depending on the route.

Namespace

Drupal\Core\Routing

Code

public function filter(RouteCollection $collection, Request $request) {
  $filter_ids = [];
  foreach ($collection
    ->all() as $route) {
    $filter_ids = array_merge($filter_ids, $route
      ->getOption('_route_filters') ?: []);
  }
  $filter_ids = array_unique($filter_ids);
  if (isset($filter_ids)) {
    foreach ($filter_ids as $filter_id) {
      if ($filter = $this->container
        ->get($filter_id, ContainerInterface::NULL_ON_INVALID_REFERENCE)) {
        $collection = $filter
          ->filter($collection, $request);
      }
    }
  }
  return $collection;
}