CompiledRouteCollection
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
Determine if a route in the array matches the request.
Get a route (if necessary) that responds when other available methods are present.
Throw a method not allowed HTTP exception.
Return the CompiledUrlMatcherDumper instance for the route collection.
Convert the collection to a Symfony RouteCollection instance.
Add a route to the SymfonyRouteCollection instance.
Get the route instances that should be pre-warmed.
Create a new CompiledRouteCollection instance.
Determine whether the compiled matcher contains scheme-constrained routes.
Determine whether any compiled route requires a specific server port.
Ensure a dynamically-added route doesn't conflict with a compiled route on port.
Build the port lookup map from compiled route attributes.
Refresh the name look-up table.
Refresh the action look-up table.
Match an unconstrained exact path without constructing Symfony matcher state.
Get routes from the collection by method.
Determine if the route collection contains a given named route.
Get a route instance by its controller action.
Get all of the routes in the collection.
Get all of the routes keyed by their HTTP verb / method.
Get all of the routes keyed by their name.
Get the cached route names grouped by the HTTP method they respond to.
Get the cached route names keyed by their controller action.
Details
in
AbstractRouteCollection at line 27
protected Route
handleMatchedRoute(Request $request, Route|null $route)
Handle the matched route.
in
AbstractRouteCollection at line 53
protected array
checkForAlternateVerbs(Request $request)
Determine if any routes match on another HTTP verb.
in
AbstractRouteCollection at line 73
protected Route|null
matchAgainstRoutes(array $routes, Request $request, bool $includingMethod = true)
Determine if a route in the array matches the request.
in
AbstractRouteCollection at line 99
protected Route
getRouteForMethods(Request $request, array $methods)
Get a route (if necessary) that responds when other available methods are present.
in
AbstractRouteCollection at line 115
protected never
requestMethodNotAllowed(Request $request, array $others, string $method)
Throw a method not allowed HTTP exception.
in
AbstractRouteCollection at line 131
array
compile()
Compile the routes for caching.
in
AbstractRouteCollection at line 159
CompiledUrlMatcherDumper
dumper()
Return the CompiledUrlMatcherDumper instance for the route collection.
in
AbstractRouteCollection at line 167
RouteCollection
toSymfonyRouteCollection()
Convert the collection to a Symfony RouteCollection instance.
in
AbstractRouteCollection at line 195
protected RouteCollection
addToSymfonyRoutesCollection(RouteCollection $symfonyRoutes, Route $route)
Add a route to the SymfonyRouteCollection instance.
in
AbstractRouteCollection at line 223
protected string
generateRouteName()
Get a randomly generated route name.
at line 511
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.
in
AbstractRouteCollection at line 248
Traversable
getIterator()
Get an iterator for the items.
in
AbstractRouteCollection at line 256
int
count()
Count the number of items in the collection.
at line 120
__construct(array $compiled, array $attributes)
Create a new CompiledRouteCollection instance.
at line 147
protected bool
compiledRoutesRequireScheme(array $compiled)
Determine whether the compiled matcher contains scheme-constrained routes.
at line 165
protected bool
compiledRoutesHavePortConstraints(array $attributes)
Determine whether any compiled route requires a specific server port.
at line 196
protected void
ensureNoCrossPortConflictWithCompiledRoutes(Route $route)
Ensure a dynamically-added route doesn't conflict with a compiled route on port.
at line 221
protected array
buildCompiledPortMap()
Build the port lookup map from compiled route attributes.
at line 241
void
refreshNameLookups()
Refresh the name look-up table.
This is done in case any names are fluently defined or if routes are overwritten.
at line 250
void
refreshActionLookups()
Refresh the action look-up table.
This is done in case any actions are overwritten with new controllers.
at line 271
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, which is matched and given to compiled conditions as the trimmed request Laravel matches against would give it. The request itself keeps the URI it arrived with, avoiding the overhead of cloning the entire Request object.
at line 401
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.
at line 428
array
get(string|null $method = null)
Get routes from the collection by method.
at line 449
bool
hasNamedRoute(string $name)
Determine if the route collection contains a given named route.
at line 459
Route|null
getByName(string $name)
Get a route instance by its name.
Returns cached Route objects for the lifetime of this collection.
at line 475
Route|null
getByAction(string $action)
Get a route instance by its controller action.
at line 491
array
getRoutes()
Get all of the routes in the collection.
at line 527
array
getRoutesByMethod()
Get all of the routes keyed by their HTTP verb / method.
at line 542
array
getRoutesByName()
Get all of the routes keyed by their name.
at line 556
protected array
routeNamesByMethod()
Get the cached route names grouped by the HTTP method they respond to.
at line 575
protected array
routeNameByAction()
Get the cached route names keyed by their controller action.
at line 595
protected Route
newRoute(array $attributes)
Resolve an array of attributes to a Route instance.
at line 626
CompiledRouteCollection
setRouter(Router $router)
Set the router instance on the route.
at line 641
CompiledRouteCollection
setContainer(Container $container)
Set the container instance on the route.
Swaps the container reference on the route collection used by the singleton Router; per-request use races across coroutines.