class RouteProvider implements CacheableRouteProviderInterface, PreloadableRouteProviderInterface, PagedRouteProviderInterface, EventSubscriberInterface (View source)

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

Constants

ROUTE_LOAD_CID_PREFIX

Cache ID prefix used to load routes.

Properties

protected Connection $connection

The database connection from which to read route information.

protected string $tableName

The name of the SQL table from which to read the routes.

protected StateInterface $state

The state.

protected Route[] $routes

A cache of already-loaded routes, keyed by route name.

protected string[] $serializedRoutes

A cache of already-loaded serialized routes, keyed by route name.

protected CurrentPathStack $currentPath

The current path.

protected CacheBackendInterface $cache

The cache backend.

protected CacheTagsInvalidatorInterface $cacheTagInvalidator

The cache tag invalidator.

protected InboundPathProcessorInterface $pathProcessor

A path processor manager for resolving the system path.

protected LanguageManagerInterface $languageManager

The language manager.

protected string[] $extraCacheKeyParts

An array of cache key parts to be used for the route match cache.

Methods

__construct(Connection $connection, StateInterface $state, CurrentPathStack $current_path, CacheBackendInterface $cache_backend, InboundPathProcessorInterface $path_processor, CacheTagsInvalidatorInterface $cache_tag_invalidator, string $table = 'router', LanguageManagerInterface $language_manager = NULL)

Constructs a new PathMatcher.

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.

getRoutesByNames($names)

{@inheritdoc}

array
getCandidateOutlines(array $parts)

Returns an array of path pattern outlines that could match the path parts.

RouteCollection
getRoutesByPattern(string $pattern)

Get all routes which match a certain pattern.

RouteCollection
getRoutesByPath(string $path)

Get all routes which match a certain pattern.

routeProviderRouteCompare(array $a, array $b)

Comparison function for usort on routes.

Route[]
getAllRoutes()

Returns all the routes on the system.

reset()

Resets the route provider object.

static 
getSubscribedEvents()

{@inheritdoc}

getRoutesPaged($offset, $length = NULL)

{@inheritdoc}

getRoutesCount()

{@inheritdoc}

addExtraCacheKeyPart(string $cache_key_provider, string $cache_key_part)

Adds a cache key part to be used in the cache ID of the route collection.

string
getRouteCollectionCacheId(Request $request)

Returns the cache ID for the route collection cache.

string
getCurrentLanguageCacheIdPart()

Returns the language identifier for the route collection cache.

Details

__construct(Connection $connection, StateInterface $state, CurrentPathStack $current_path, CacheBackendInterface $cache_backend, InboundPathProcessorInterface $path_processor, CacheTagsInvalidatorInterface $cache_tag_invalidator, string $table = 'router', LanguageManagerInterface $language_manager = NULL)

Constructs a new PathMatcher.

Parameters

Connection $connection

A database connection object.

StateInterface $state

The state.

CurrentPathStack $current_path

The current path.

CacheBackendInterface $cache_backend

The cache backend.

InboundPathProcessorInterface $path_processor

The path processor.

CacheTagsInvalidatorInterface $cache_tag_invalidator

The cache tag invalidator.

string $table

(Optional) The table in the database to use for matching. Defaults to 'router'

LanguageManagerInterface $language_manager

(Optional) The language manager.

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

RouteCollection with all urls that could potentially match $request. Empty collection if nothing can match. The collection 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 getRouteByName(string $name)

Find the route using the provided route name.

Parameters

string $name

The route name to fetch

Return Value

Route

The found route.

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.

getRoutesByNames($names)

{@inheritdoc}

Parameters

$names

protected array getCandidateOutlines(array $parts)

Returns an array of path pattern outlines that could match the path parts.

Parameters

array $parts

The parts of the path for which we want candidates.

Return Value

array

An array of outlines that could match the specified path parts.

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.

protected RouteCollection getRoutesByPath(string $path)

Get all routes which match a certain pattern.

Parameters

string $path

The route pattern to search for.

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.

protected routeProviderRouteCompare(array $a, array $b)

Comparison function for usort on routes.

Parameters

array $a
array $b

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.

static getSubscribedEvents()

{@inheritdoc}

getRoutesPaged($offset, $length = NULL)

{@inheritdoc}

Parameters

$offset
$length

getRoutesCount()

{@inheritdoc}

addExtraCacheKeyPart(string $cache_key_provider, string $cache_key_part)

Adds a cache key part to be used in the cache ID of the route collection.

Parameters

string $cache_key_provider

The provider of the cache key part.

string $cache_key_part

A string to be used as a cache key part.

protected string getRouteCollectionCacheId(Request $request)

Returns the cache ID for the route collection cache.

Parameters

Request $request

The request object.

Return Value

string

The cache ID.

protected string getCurrentLanguageCacheIdPart()

Returns the language identifier for the route collection cache.

Return Value

string

The language identifier.