class RoutePreloader implements EventSubscriberInterface (View source)

Defines a class which preloads non-admin routes.

On an actual site we want to avoid too many database queries so we build a list of all routes which most likely appear on the actual site, which are all HTML routes not starting with "/admin".

Properties

protected RouteProviderInterface|PreloadableRouteProviderInterface $routeProvider

The route provider.

protected StateInterface $state

The state key value store.

protected array $nonAdminRoutesOnRebuild

Contains the non-admin routes while rebuilding the routes.

protected CacheBackendInterface $cache

The cache backend used to skip the state loading.

Methods

__construct(RouteProviderInterface $route_provider, StateInterface $state, CacheBackendInterface $cache)

Constructs a new RoutePreloader.

onRequest(KernelEvent $event)

Loads all non-admin routes right before the actual page is rendered.

onAlterRoutes(RouteBuildEvent $event)

Alters existing routes for a specific collection.

onFinishedRoutes()

Store the non admin routes in state when the route building is finished.

static 
getSubscribedEvents()

{@inheritdoc}

static bool
isGetAndHtmlRoute(Route $route)

Determines whether the given route is a GET and HTML route.

Details

__construct(RouteProviderInterface $route_provider, StateInterface $state, CacheBackendInterface $cache)

Constructs a new RoutePreloader.

Parameters

RouteProviderInterface $route_provider

The route provider.

StateInterface $state

The state key value store.

CacheBackendInterface $cache

The cache backend.

onRequest(KernelEvent $event)

Loads all non-admin routes right before the actual page is rendered.

Parameters

KernelEvent $event

The event to process.

onAlterRoutes(RouteBuildEvent $event)

Alters existing routes for a specific collection.

Parameters

RouteBuildEvent $event

The route build event.

onFinishedRoutes()

Store the non admin routes in state when the route building is finished.

static getSubscribedEvents()

{@inheritdoc}

static protected bool isGetAndHtmlRoute(Route $route)

Determines whether the given route is a GET and HTML route.

Parameters

Route $route

The route to analyze.

Return Value

bool

TRUE if GET is a valid method and HTML is a valid format for this route.