class RouteProviderLazyBuilder implements PreloadableRouteProviderInterface, EventSubscriberInterface (View source)

A Route Provider front-end for all Drupal-stored routes.

Properties

protected RouteProviderInterface $routeProvider

The route provider service.

protected RouteBuilderInterface $routeBuilder

The route building service.

protected bool $rebuilt

Flag to determine if the router has been rebuilt.

protected bool $rebuilding

Flag to determine if router is currently being rebuilt.

Methods

__construct(RouteProviderInterface $route_provider, RouteBuilderInterface $route_builder)

RouteProviderLazyBuilder constructor.

getRouteProvider()

Gets the real route provider service and rebuilds the router id necessary.

RouteCollection
getRouteCollectionForRequest(Request $request)

Finds routes that may potentially match the request.

Route
getRouteByName(string $name)

Find the route using the provided route name.

preLoadRoutes(string[] $names)

Pre-load routes by their names using the provided list of names.

Route[]
getRoutesByNames(array|null $names)

Find many routes by their names using the provided list of names.

RouteCollection
getRoutesByPattern(string $pattern)

Get all routes which match a certain pattern.

Route[]
getAllRoutes()

Returns all the routes on the system.

reset()

Resets the route provider object.

Route[]
getRoutesPaged(int $offset, int $length = NULL) deprecated

Returns a chunk of routes.

int
getRoutesCount() deprecated

Gets the total count of routes provided by the router.

bool
hasRebuilt()

Determines if the router has been rebuilt.

static 
getSubscribedEvents()

{@inheritdoc}

routerRebuilding()

Sets the router rebuilding flag to TRUE.

routerRebuildFinished()

Sets the router rebuilding flag to FALSE.

Details

__construct(RouteProviderInterface $route_provider, RouteBuilderInterface $route_builder)

RouteProviderLazyBuilder constructor.

Parameters

RouteProviderInterface $route_provider

The route provider service.

RouteBuilderInterface $route_builder

The route building service.

protected RouteProviderInterface getRouteProvider()

Gets the real route provider service and rebuilds the router id necessary.

Return Value

RouteProviderInterface

The route provider service.

RouteCollection getRouteCollectionForRequest(Request $request)

Finds routes that may potentially match the request.

This may return a mixed list of class instances, but all routes returned must extend the core Symfony route. The classes may also implement RouteObjectInterface to link to a content document.

This method may not throw an exception based on implementation specific restrictions on the url. That case is considered a not found - returning an empty array. Exceptions are only used to abort the whole request in case something is seriously broken, like the storage backend being down.

Note that implementations may not implement an optimal matching algorithm, simply a reasonable first pass. That allows for potentially very large route sets to be filtered down to likely candidates, which may then be filtered in memory more completely.

Parameters

Request $request

A request against which to match

Return Value

RouteCollection

All Routes that could potentially match $request. Empty collection if nothing can match

Route getRouteByName(string $name)

Find the route using the provided route name.

Parameters

string $name

The route name to fetch

Return Value

Route

The Symfony route object.

Exceptions

RouteNotFoundException

preLoadRoutes(string[] $names)

Pre-load routes by their names using the provided list of names.

This method exists in order to allow performance optimizations. It allows pre-loading serialized routes that may latter be retrieved using ::getRoutesByName()

Parameters

string[] $names

Array of route names to load.

Route[] getRoutesByNames(array|null $names)

Find many routes by their names using the provided list of names.

Note that this method may not throw an exception if some of the routes are not found or are not actually Route instances. It will just return the list of those Route instances it found.

This method exists in order to allow performance optimizations. The simple implementation could be to just repeatedly call $this->getRouteByName() while catching and ignoring eventual exceptions.

If $names is null, this method SHOULD return a collection of all routes known to this provider. If there are many routes to be expected, usage of a lazy loading collection is recommended. A provider MAY only return a subset of routes to e.g. support paging or other concepts.

Parameters

array|null $names

The list of names to retrieve, In case of null, the provider will determine what routes to return

Return Value

Route[]

Iterable list with the keys being the names from the $names array

RouteCollection getRoutesByPattern(string $pattern)

Get all routes which match a certain pattern.

Parameters

string $pattern

The route pattern to search for (contains } as placeholders).

Return Value

RouteCollection

Returns a route collection of matching routes. The collection may be empty and will be sorted from highest to lowest fit (match of path parts) and then in ascending order by route name for routes with the same fit.

Route[] getAllRoutes()

Returns all the routes on the system.

Usage of this method is discouraged for performance reasons. If possible, use RouteProviderInterface::getRoutesByNames() or RouteProviderInterface::getRoutesByPattern() instead.

Return Value

Route[]

An iterator of routes keyed by route name.

reset()

Resets the route provider object.

Route[] getRoutesPaged(int $offset, int $length = NULL) deprecated

deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct replacement is provided.

Returns a chunk of routes.

Should only be used in conjunction with an iterator.

Parameters

int $offset

The query offset.

int $length

The number of records.

Return Value

Route[]

Routes keyed by the route name.

See also

https://www.drupal.org/node/3151009

int getRoutesCount() deprecated

deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. No direct replacement is provided.

Gets the total count of routes provided by the router.

Return Value

int

Number of routes.

See also

https://www.drupal.org/node/3151009

bool hasRebuilt()

Determines if the router has been rebuilt.

Return Value

bool

TRUE is the router has been rebuilt, FALSE if not.

static getSubscribedEvents()

{@inheritdoc}

routerRebuilding()

Sets the router rebuilding flag to TRUE.

routerRebuildFinished()

Sets the router rebuilding flag to FALSE.