October\Rain\Router\RouteCompiler
Overview
RouteCompiler transforms route rules into optimized lookup structures, similar to Laravel's cached routes and Symfony's compiled URL matcher.
- Fully static routes are collected in a hash map for O(1) lookup.
- Dynamic routes are combined into regexes bucketed by their first static segment, using the PCRE (*MARK) verb so one preg_match call identifies the matched route.
- Wildcard routes use capture logic that cannot be expressed in the combined regex, they are matched sequentially by the router.
Custom segment expressions (:param|^regex$) are intentionally not inlined in the combined regex. They are validated after the structural match using the same logic as Rule::resolveUrlSegments, preserving their original semantics (case sensitivity, substring search, error tolerance).
The route map must be sorted (see Router::sortRules) before compiling, positions recorded here refer to offsets in the sorted route map.
Public Methods
public static compile()
public static compile(array $routeMap): array
compile transforms route rules into optimized lookup structures
Protected Methods
protected static compileRulePattern()
protected static compileRulePattern(Rule $rule): array
compileRulePattern converts a rule to a regex branch with parameter metadata. Segments with custom expressions match as generic segments ([^/]+) and are validated after the match, so the combined regex never embeds user patterns.