Skip to content

CompiledMatcherDumper

Back-end that dumps a RouteCollection to a Symfony CompiledUrlMatcher blob (the same technique Symfony’s own router uses: a static-prefix tree + merged regexes emitted as plain PHP, so matching is opcache-native instead of iterating/compiling the collection at runtime).

Slots in alongside RouteCollectionBuilder as a sibling back-end over the routing IR.

Staleness safety: the artifact is written to a path keyed by a signature of the route definitions. If the routes change and the dump is not regenerated, the live signature no longer matches any file on disk, so Routing silently falls back to the dynamic UrlMatcher — a stale dump can never route a request to the wrong action.

final class CompiledMatcherDumper

Since1.0.0
SourceRouting/Compiler/CompiledMatcherDumper.php
MethodDescription
emit(RouteCollection $routes): EmittedArtifactEmit the compiled-routes PHP (a file that returns the array CompiledUrlMatcher’s constructor expects), without writing it.
signature(RouteCollection $routes): stringShort, stable hash of everything about the collection that affects matching (name, path, methods, host, requirements, defaults, condition), in collection order (order is significant for same-path routes).
targetFor(RouteCollection $routes): stringThe path the compiled matcher for these routes is written to / loaded from — under the app cache dir, keyed by the route signature.
targetForSignature(string $signature): stringThe artifact path for an already-computed route signature, under core.cache_dir’s routing/ directory.

public static function emit(RouteCollection $routes): EmittedArtifact

Emit the compiled-routes PHP (a file that returns the array CompiledUrlMatcher’s constructor expects), without writing it.

ParameterTypeDescription
$routesRouteCollection

Returns EmittedArtifact

public static function signature(RouteCollection $routes): string

Short, stable hash of everything about the collection that affects matching (name, path, methods, host, requirements, defaults, condition), in collection order (order is significant for same-path routes).

ParameterTypeDescription
$routesRouteCollection

Returns string

public static function targetFor(RouteCollection $routes): string

The path the compiled matcher for these routes is written to / loaded from — under the app cache dir, keyed by the route signature.

ParameterTypeDescription
$routesRouteCollection

Returns string

public static function targetForSignature(string $signature): string

The artifact path for an already-computed route signature, under core.cache_dir’s routing/ directory.

Lets a caller that holds a signature — a runtime lookup checking whether a dump for the live routes exists — avoid re-hashing the collection.

ParameterTypeDescription
$signaturestring

Returns string