class CompiledRouteCollection extends AbstractRouteCollection

Properties

protected array $compiled

The compiled routes collection.

protected array $attributes

An array of the route attributes keyed by name.

protected RouteCollection|null $routes

The dynamically added routes that were added after loading the cached, compiled routes.

protected bool $hasDynamicRoutes

Whether routes have been added after this collection was compiled.

protected Router $router

The router instance used by the route.

protected Container $container

The container instance used by the route.

protected Route> $nameCache

A cache of resolved Route instances keyed by route name.

protected RequestContext $requestContextPrototype

An immutable request context template cloned for each match.

protected bool $requiresScheme

Whether any compiled route has a scheme constraint.

protected bool $requiresFullRequestContext

Whether compiled route conditions require the complete request context.

protected bool $hasPortConstraints

Whether any compiled route has a port constraint.

protected bool $supportsDirectStaticMatching

Whether exact static routes need only path, method, and slash checks.

protected array $compiledWithoutStaticRoutes

The compiled matcher state used after an exact static path miss.

protected null|array<string, array<int, string>> $routeNamesByMethod

A cache of route names grouped by the HTTP method they respond to, built from the route attributes.

protected null|array<string, string> $routeNameByAction

A cache of route names keyed by their controller action, built from the route attributes.

protected null|array<string, null|int> $compiledPortMap

Port lookup map for compiled routes, keyed by "METHOD domain+uri".

Methods

handleMatchedRoute(Request $request, Route|null $route)

Handle the matched route.

array
checkForAlternateVerbs(Request $request)

Determine if any routes match on another HTTP verb.

Route|null
matchAgainstRoutes(array $routes, Request $request, bool $includingMethod = true)

Determine if a route in the array matches the request.

getRouteForMethods(Request $request, array $methods)

Get a route (if necessary) that responds when other available methods are present.

never
requestMethodNotAllowed(Request $request, array $others, string $method)

Throw a method not allowed HTTP exception.

array
compile()

Compile the routes for caching.

CompiledUrlMatcherDumper
dumper()

Return the CompiledUrlMatcherDumper instance for the route collection.

RouteCollection
toSymfonyRouteCollection()

Convert the collection to a Symfony RouteCollection instance.

RouteCollection
addToSymfonyRoutesCollection(RouteCollection $symfonyRoutes, Route $route)

Add a route to the SymfonyRouteCollection instance.

string
generateRouteName()

Get a randomly generated route name.

array
getWarmableRoutes()

Get the route instances that should be pre-warmed.

getIterator()

Get an iterator for the items.

int
count()

Count the number of items in the collection.

__construct(array $compiled, array $attributes)

Create a new CompiledRouteCollection instance.

bool
compiledRoutesRequireScheme(array $compiled)

Determine whether the compiled matcher contains scheme-constrained routes.

bool
compiledRoutesHavePortConstraints(array $attributes)

Determine whether any compiled route requires a specific server port.

add(Route $route)

Add a Route instance to the collection.

void
ensureNoCrossPortConflictWithCompiledRoutes(Route $route)

Ensure a dynamically-added route doesn't conflict with a compiled route on port.

array
buildCompiledPortMap()

Build the port lookup map from compiled route attributes.

void
refreshNameLookups()

Refresh the name look-up table.

void
refreshActionLookups()

Refresh the action look-up table.

match(Request $request)

Find the first route matching a given request.

array|null
matchDirectStaticRoute(string $method, string $path, array $routes)

Match an unconstrained exact path without constructing Symfony matcher state.

array
get(string|null $method = null)

Get routes from the collection by method.

bool
hasNamedRoute(string $name)

Determine if the route collection contains a given named route.

Route|null
getByName(string $name)

Get a route instance by its name.

Route|null
getByAction(string $action)

Get a route instance by its controller action.

array
getRoutes()

Get all of the routes in the collection.

array
getRoutesByMethod()

Get all of the routes keyed by their HTTP verb / method.

array
getRoutesByName()

Get all of the routes keyed by their name.

array
routeNamesByMethod()

Get the cached route names grouped by the HTTP method they respond to.

array
routeNameByAction()

Get the cached route names keyed by their controller action.

newRoute(array $attributes)

Resolve an array of attributes to a Route instance.

setRouter(Router $router)

Set the router instance on the route.

setContainer(Container $container)

Set the container instance on the route.

Details

protected Route handleMatchedRoute(Request $request, Route|null $route)

Handle the matched route.

Parameters

Request $request
Route|null $route

Return Value

Route

Exceptions

NotFoundHttpException

protected array checkForAlternateVerbs(Request $request)

Determine if any routes match on another HTTP verb.

Parameters

Request $request

Return Value

array

protected Route|null matchAgainstRoutes(array $routes, Request $request, bool $includingMethod = true)

Determine if a route in the array matches the request.

Parameters

array $routes
Request $request
bool $includingMethod

Return Value

Route|null

protected Route getRouteForMethods(Request $request, array $methods)

Get a route (if necessary) that responds when other available methods are present.

Parameters

Request $request
array $methods

Return Value

Route

Exceptions

MethodNotAllowedHttpException

protected never requestMethodNotAllowed(Request $request, array $others, string $method)

Throw a method not allowed HTTP exception.

Parameters

Request $request
array $others
string $method

Return Value

never

Exceptions

MethodNotAllowedHttpException

array compile()

Compile the routes for caching.

Return Value

array

CompiledUrlMatcherDumper dumper()

Return the CompiledUrlMatcherDumper instance for the route collection.

Return Value

CompiledUrlMatcherDumper

RouteCollection toSymfonyRouteCollection()

Convert the collection to a Symfony RouteCollection instance.

Return Value

RouteCollection

protected RouteCollection addToSymfonyRoutesCollection(RouteCollection $symfonyRoutes, Route $route)

Add a route to the SymfonyRouteCollection instance.

Parameters

RouteCollection $symfonyRoutes
Route $route

Return Value

RouteCollection

Exceptions

LogicException

protected string generateRouteName()

Get a randomly generated route name.

Return Value

string

at line 510
array getWarmableRoutes()

Get the route instances that should be pre-warmed.

Returns the collection's cached Route instances — these are the objects actually used during request matching. Unlike getRoutes() which creates fresh throwaway objects every call.

Return Value

array

Traversable getIterator()

Get an iterator for the items.

Return Value

Traversable

int count()

Count the number of items in the collection.

Return Value

int

at line 119
__construct(array $compiled, array $attributes)

Create a new CompiledRouteCollection instance.

Parameters

array $compiled
array $attributes

at line 146
protected bool compiledRoutesRequireScheme(array $compiled)

Determine whether the compiled matcher contains scheme-constrained routes.

Parameters

array $compiled

Return Value

bool

at line 164
protected bool compiledRoutesHavePortConstraints(array $attributes)

Determine whether any compiled route requires a specific server port.

Parameters

array $attributes

Return Value

bool

at line 180
Route add(Route $route)

Add a Route instance to the collection.

Parameters

Route $route

Return Value

Route

Exceptions

LogicException

at line 195
protected void ensureNoCrossPortConflictWithCompiledRoutes(Route $route)

Ensure a dynamically-added route doesn't conflict with a compiled route on port.

Parameters

Route $route

Return Value

void

Exceptions

LogicException

at line 220
protected array buildCompiledPortMap()

Build the port lookup map from compiled route attributes.

Return Value

array

at line 240
void refreshNameLookups()

Refresh the name look-up table.

This is done in case any names are fluently defined or if routes are overwritten.

Return Value

void

at line 249
void refreshActionLookups()

Refresh the action look-up table.

This is done in case any actions are overwritten with new controllers.

Return Value

void

at line 269
Route match(Request $request)

Find the first route matching a given request.

Clone an immutable RequestContext template per request for coroutine safety. A shared mutable context would race under coroutine interleaving. Ordinary routes populate only method and validated host; scheme and complete request metadata are resolved only when the compiled route table requires them.

No request duplication needed — trailing slashes are trimmed via rtrim() on the path string and passed to match() directly, avoiding the overhead of cloning the entire Request object. RequestBridge also normalizes trailing slashes for real HTTP requests upstream.

Parameters

Request $request

Return Value

Route

Exceptions

MethodNotAllowedHttpException
NotFoundHttpException

at line 400
protected array|null matchDirectStaticRoute(string $method, string $path, array $routes)

Match an unconstrained exact path without constructing Symfony matcher state.

Null means a static path existed but Symfony must resolve method or slash semantics. Encoded paths never reach this method; the caller defers them to Symfony before the table lookup.

Parameters

string $method
string $path
array $routes

Return Value

array|null

at line 427
array get(string|null $method = null)

Get routes from the collection by method.

Parameters

string|null $method

Return Value

array

at line 448
bool hasNamedRoute(string $name)

Determine if the route collection contains a given named route.

Parameters

string $name

Return Value

bool

at line 458
Route|null getByName(string $name)

Get a route instance by its name.

Returns cached Route objects for the lifetime of this collection.

Parameters

string $name

Return Value

Route|null

at line 474
Route|null getByAction(string $action)

Get a route instance by its controller action.

Parameters

string $action

Return Value

Route|null

at line 490
array getRoutes()

Get all of the routes in the collection.

Return Value

array

at line 526
array getRoutesByMethod()

Get all of the routes keyed by their HTTP verb / method.

Return Value

array

at line 541
array getRoutesByName()

Get all of the routes keyed by their name.

Return Value

array

at line 555
protected array routeNamesByMethod()

Get the cached route names grouped by the HTTP method they respond to.

Return Value

array

at line 574
protected array routeNameByAction()

Get the cached route names keyed by their controller action.

Return Value

array

at line 594
protected Route newRoute(array $attributes)

Resolve an array of attributes to a Route instance.

Parameters

array $attributes

Return Value

Route

at line 624
CompiledRouteCollection setRouter(Router $router)

Set the router instance on the route.

Parameters

Router $router

Return Value

CompiledRouteCollection

at line 639
CompiledRouteCollection setContainer(Container $container)

Set the container instance on the route.

Tests only. Swaps the container reference on the route collection used by the singleton Router; per-request use races across coroutines.

Parameters

Container $container

Return Value

CompiledRouteCollection