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 Router $router

The router instance used by the route.

protected Container $container

The container instance used by the route.

protected Route> $cachedRoutesByName

Pre-built Route objects keyed by name for this collection.

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.

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
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.

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 292
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 65
__construct(array $compiled, array $attributes)

Create a new CompiledRouteCollection instance.

Parameters

array $compiled
array $attributes

at line 77
Route add(Route $route)

Add a Route instance to the collection.

Parameters

Route $route

Return Value

Route

Exceptions

LogicException

at line 89
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 114
protected array buildCompiledPortMap()

Build the port lookup map from compiled route attributes.

Return Value

array

at line 134
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 143
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 162
Route match(Request $request)

Find the first route matching a given request.

Fresh RequestContext per request for coroutine safety — a shared mutable RequestContext would race under coroutine interleaving. The allocation cost of one small object per request is negligible.

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 219
array get(string|null $method = null)

Get routes from the collection by method.

Parameters

string|null $method

Return Value

array

at line 227
bool hasNamedRoute(string $name)

Determine if the route collection contains a given named route.

Parameters

string $name

Return Value

bool

at line 237
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 250
Route|null getByAction(string $action)

Get a route instance by its controller action.

Parameters

string $action

Return Value

Route|null

at line 272
array getRoutes()

Get all of the routes in the collection.

Return Value

array

at line 308
array getRoutesByMethod()

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

Return Value

array

at line 327
array getRoutesByName()

Get all of the routes keyed by their name.

Return Value

array

at line 339
protected Route newRoute(array $attributes)

Resolve an array of attributes to a Route instance.

Parameters

array $attributes

Return Value

Route

at line 369
CompiledRouteCollection setRouter(Router $router)

Set the router instance on the route.

Parameters

Router $router

Return Value

CompiledRouteCollection

at line 384
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