Skip to content

Routing

Base class for an application’s route table, and the matcher and URL generator built from it.

An application subclasses this and implements Routing::build(), returning the Symfony RouteCollection plus the parallel meta array holding the Quiote-specific per-route data (generation pattern, parent linkage, the cut flag). Typical implementations return a generated route aggregate’s build() result, merge #[Route]-attributed routes into it with AttributeRoutes::mergeInto(), or both. The subclass is named in factories.xml (<routing class="..."/>) and one instance is created per Context; collaborators take it as a constructor dependency or resolve Routing::class from the container instead of constructing one.

build() runs from the constructor, so the table is complete before the object is usable. Routing::match() prefers a precompiled Symfony matcher dumped by quiote cache:warmup and falls back to the dynamic matcher when none exists, when the dump no longer matches the route definitions, or when core.routing.compiled_matcher is false. Routing::addRoute() and Routing::importRoutes() change the table at runtime and invalidate the matcher, which is then rebuilt dynamically on the next match; Routing::exportRoutes() round-trips the whole table back out.

URL generation is Routing::gen() — by route name, or a self-referential URL when given null — and Routing::genSelf(). Routing::getBaseHref() composes the absolute origin those URLs are rooted at from the request and its proxy headers, passing the resulting host through the core.trusted_hosts allow-list. During a request RoutingMiddleware drives the matching and keeps the Symfony RequestContext returned by Routing::getRequestContext() in step with the incoming HTTP method.

abstract class Routing implements ContextComponentInterface, ResetInterface

ImplementsContextComponentInterface, ResetInterface
SourceRouting/Routing.php
PropertyTypeDescription
$context?Contextprotected.
$initializedboolprotected.
$inputstringprotected.
$inputParametersarrayprotected.
$legacyGeneratedarrayprotected.
$parametersarrayprotected.
$sourcesarrayprotected.
$startedboolprotected.

public function __construct(?RequestContext $requestContext = null): mixed

ParameterTypeDescription
$requestContext?``RequestContext

Returns mixed

MethodDescription
[`addRoute(string $pattern, array<string, mixed> $opts = [], stringnull $parent = null): string`](#addroute)
[`build(): array{0: RouteCollection, 1: array<string, array{gen_path: string, cut: bool, path: string, opt?: array{parent: (stringnull), action: mixed}, pattern?: string, match_full?: string, match_partial?: string}>}`](#build)
[`exportRoutes(): array{0: RouteCollection, 1: array<string, array{gen_path: string, cut: bool, path: string, opt?: array{parent: (stringnull), action: mixed}, pattern?: string, match_full?: string, match_partial?: string}>}`](#exportroutes)
[`gen(stringnull $route, array<string, mixed> $params = [], array<string, mixed> $options = []): string`](#gen)
genSelf(?string $routeName, array<string, mixed> $params = [], array<string, mixed> $currentQuery = []): string
getBaseHref(): stringReturn the absolute origin (scheme://host[:port]) without trailing slash.
getBasePath(): stringReturns the path generated URLs are rooted at.
[`getMeta(): array<string, array{gen_path: string, cut: bool, path: string, opt?: array{parent: (stringnull), action: mixed}, pattern?: string, match_full?: string, match_partial?: string}>`](#getmeta)
getRequestContext(): RequestContextReturns the Symfony request context matching and URL generation run against.
[`getRoute(string $name): array{gen_path: string, cut: bool, path: string, opt?: array{parent: (stringnull), action: mixed}, pattern?: string, match_full?: string, match_partial?: string}
getRouteCollection(): RouteCollectionReturns the Symfony route collection the routing matches and generates against.
importRoutes(array<int, mixed> $spec): voidImport an entire RouteCollection + meta array, replacing current state.
initialize(Context $context, array<string, mixed> $parameters = []): voidLegacy initialize() hook – stores Context & parameters and marks initialized.
isEnabled(): boolIndicates whether routing should be considered enabled (subclasses override).
match(string $path): array<string, mixed>
parseRouteString(string $routeString): array{0: string, 1: string, 2: array<string, array{name: string, pre: string, val: string, post: string, is_optional: bool}>, 3: int}
reset(): voidReset state for worker reuse (FrankenPHP etc).
startup(): voidLegacy startup() hook.

public function addRoute(string $pattern, array<string, mixed> $opts = [], string|null $parent = null): string

Add a route dynamically.

Parent route name for hierarchy.

ParameterTypeDescription
$patternstringRaw pattern (may be relative if parent provided)
$optsarray``<``string``, ``mixed``>Route options: name (optional), module, action, defaults[] etc.
$parent`string““null`

Returns string — Final route name.

ThrowsWhen
QuioteExceptionon conflicting duplicate name with different parent.

abstract protected function build(): array{0: RouteCollection, 1: array<string, array{gen_path: string, cut: bool, path: string, opt?: array{parent: (string | null), action: mixed}, pattern?: string, match_full?: string, match_partial?: string}>}

Returns array{0: RouteCollection, 1: array<string, array{gen_path: string, cut: bool, path: string, opt?: array{parent: (string | null), action: mixed}, pattern?: string, match_full?: string, match_partial?: string}>}

public function exportRoutes(): array{0: RouteCollection, 1: array<string, array{gen_path: string, cut: bool, path: string, opt?: array{parent: (string | null), action: mixed}, pattern?: string, match_full?: string, match_partial?: string}>}

Export current routing definition (RouteCollection + meta) so RoutingMiddleware can wire it up for dispatch, and so it can be round-tripped back through importRoutes().

Returns array{0: RouteCollection, 1: array<string, array{gen_path: string, cut: bool, path: string, opt?: array{parent: (string | null), action: mixed}, pattern?: string, match_full?: string, match_partial?: string}>}

public function gen(string|null $route, array<string, mixed> $params = [], array<string, mixed> $options = []): string

URL generation.

ParameterTypeDescription
$route`string““null`
$paramsarray``<``string``, ``mixed``>
$optionsarray``<``string``, ``mixed``>

Returns string

public function genSelf(?string $routeName, array<string, mixed> $params = [], array<string, mixed> $currentQuery = []): string

ParameterTypeDescription
$routeName?``string
$paramsarray``<``string``, ``mixed``>
$currentQueryarray``<``string``, ``mixed``>

Returns string

public function getBaseHref(): string

Return the absolute origin (scheme://host[:port]) without trailing slash.

Historically this returned just ’/’, but modern usage (templates, redirects) expects a fully qualified origin for constructing absolute URLs.

Returns string

public function getBasePath(): string

Returns the path generated URLs are rooted at.

Always /. Use Routing::getBaseHref() for the absolute origin (scheme, host and port) needed to build a fully qualified URL.

Returns string

public function getMeta(): array<string, array{gen_path: string, cut: bool, path: string, opt?: array{parent: (string | null), action: mixed}, pattern?: string, match_full?: string, match_partial?: string}>

Returns array``<``string``, ``array{gen_path: string, cut: bool, path: string, opt?: array{parent: (string | null), action: mixed}, pattern?: string, match_full?: string, match_partial?: string}``>

public function getRequestContext(): RequestContext

Returns the Symfony request context matching and URL generation run against.

The same instance the routing keeps, so mutating it (scheme, host, base URL, path info) changes how subsequent matches and generated URLs resolve.

Returns RequestContext

public function getRoute(string $name): array{gen_path: string, cut: bool, path: string, opt?: array{parent: (string | null), action: mixed}, pattern?: string, match_full?: string, match_partial?: string}|null

Retrieve a single route meta entry or null.

ParameterTypeDescription
$namestring

Returns array{gen_path: string, cut: bool, path: string, opt?: array{parent: (string | null), action: mixed}, pattern?: string, match_full?: string, match_partial?: string}``|``null

public function getRouteCollection(): RouteCollection

Returns the Symfony route collection the routing matches and generates against.

Returns RouteCollection

public function importRoutes(array<int, mixed> $spec): void

Import an entire RouteCollection + meta array, replacing current state.

ParameterTypeDescription
$specarray``<``int``, ``mixed``>

public function initialize(Context $context, array<string, mixed> $parameters = []): void

Legacy initialize() hook – stores Context & parameters and marks initialized.

ParameterTypeDescription
$contextContext
$parametersarray``<``string``, ``mixed``>

public function isEnabled(): bool

Indicates whether routing should be considered enabled (subclasses override).

Returns bool

public function match(string $path): array<string, mixed>

ParameterTypeDescription
$pathstring

Returns array``<``string``, ``mixed``>

public function parseRouteString(string $routeString): array{0: string, 1: string, 2: array<string, array{name: string, pre: string, val: string, post: string, is_optional: bool}>, 3: int}

ParameterTypeDescription
$routeStringstring

Returns array{0: string, 1: string, 2: array<string, array{name: string, pre: string, val: string, post: string, is_optional: bool}>, 3: int}

public function reset(): void

Reset state for worker reuse (FrankenPHP etc).

public function startup(): void

Legacy startup() hook.

Marks started, no heavy logic needed.