RouterDispatcher
in package
uses
SmartObject
Builds the application {@see Router}.
Static sections (test, cron, admin, api, script, fallback) come from DI factories. Dynamic front routes come from the precomputed RouteTableSnapshot: a cache hit needs no SQL (RouteTableCache), a miss or disabled cache goes through RouteTableBuilder. The router never reads the database itself.
Table of Contents
Properties
- $container : Container
- $factoryCache : array<string, RouteFactoryInterface>
- $localeResolver : LocaleResolver
- $pageSlugTranslator : PageSlugTranslator
- $routeTableBuilder : RouteTableBuilder
- $routeTableCache : RouteTableCache
- $translators : array<int, TranslatorInterface>
Methods
- __construct() : mixed
- addTranslator() : void
- Called by the NEON decorator for every tagged translator.
- addTranslators() : void
- createRouter() : Router
- warmupTranslator() : void
- Warms up a translator by entity ids so components and presenters can preload the cache before linking.
- warmupTranslatorFromEntities() : void
- Warms up a translator from already loaded entities, without a database query.
- createDynamicRoutes() : void
- Creates the dynamic front routes from the route definitions.
- createRouteFromDefinition() : TranslatableRoute|null
- Creates a route from a {@see RouteDefinition} through its factory.
- getFactory() : RouteFactoryInterface|null
- Returns the factory instance from the cache or the DI container, falling back to `DefaultRouteFactory`.
Properties
$container read-only
private
Container
$container
$factoryCache
private
array<string, RouteFactoryInterface>
$factoryCache
= []
factory instances by class name
$localeResolver read-only
private
LocaleResolver
$localeResolver
$pageSlugTranslator read-only
private
PageSlugTranslator
$pageSlugTranslator
$routeTableBuilder read-only
private
RouteTableBuilder
$routeTableBuilder
$routeTableCache read-only
private
RouteTableCache
$routeTableCache
$translators
private
array<int, TranslatorInterface>
$translators
= []
registered translators, used for manual warmup from components
Methods
__construct()
public
__construct(Container $container, LocaleResolver $localeResolver, PageSlugTranslator $pageSlugTranslator, RouteTableBuilder $routeTableBuilder, RouteTableCache $routeTableCache, DefaultRouteFactory $defaultRouteFactory) : mixed
Parameters
- $container : Container
- $localeResolver : LocaleResolver
- $pageSlugTranslator : PageSlugTranslator
- $routeTableBuilder : RouteTableBuilder
- $routeTableCache : RouteTableCache
- $defaultRouteFactory : DefaultRouteFactory
addTranslator()
Called by the NEON decorator for every tagged translator.
public
addTranslator(TranslatorInterface $translator) : void
Parameters
- $translator : TranslatorInterface
addTranslators()
public
addTranslators(array<int, TranslatorInterface> $translators) : void
Parameters
- $translators : array<int, TranslatorInterface>
createRouter()
public
createRouter() : Router
Return values
RouterwarmupTranslator()
Warms up a translator by entity ids so components and presenters can preload the cache before linking.
public
warmupTranslator(string $translatorClass[, array<int, int>|null $ids = null ]) : void
Parameters
- $translatorClass : string
- $ids : array<int, int>|null = null
-
entity ids to load; null loads all
warmupTranslatorFromEntities()
Warms up a translator from already loaded entities, without a database query.
public
warmupTranslatorFromEntities(string $translatorClass, array<string|int, mixed> $entities) : void
Parameters
- $translatorClass : string
- $entities : array<string|int, mixed>
-
entities with translations loaded; the translator takes only its own (shared) entity and skips the rest
createDynamicRoutes()
Creates the dynamic front routes from the route definitions.
private
createDynamicRoutes(RouteList $router, array<int, RouteDefinition> $routes, string $defaultLocale) : void
Parameters
- $router : RouteList
- $routes : array<int, RouteDefinition>
- $defaultLocale : string
createRouteFromDefinition()
Creates a route from a {@see RouteDefinition} through its factory.
private
createRouteFromDefinition(RouteDefinition $definition[, string $defaultLocale = 'cs' ]) : TranslatableRoute|null
The presenter existence check already ran in the builder. Returns null when the factory cannot be created, and the route is skipped.
Parameters
- $definition : RouteDefinition
- $defaultLocale : string = 'cs'
Return values
TranslatableRoute|nullgetFactory()
Returns the factory instance from the cache or the DI container, falling back to `DefaultRouteFactory`.
private
getFactory(string $factoryClassName, int $routeId) : RouteFactoryInterface|null
The class name comes from the database (route_factory), so it is verified before the
container is asked for it.
Parameters
- $factoryClassName : string
- $routeId : int