Skip to content

Internals Router Matching RouteResolver

Stefan Crkvenjakov edited this page Oct 7, 2026 · 1 revision

router\matching\RouteResolver

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/router/matching/RouteResolver.php · Snapshot 8411f4287706.

Routing separates definition, HTTP request snapshot, matching, method policy, execution and error responses. Collaborators can be replaced through constructor injection.

Imports and dependencies

use router\http\HttpMethod;
use router\interface\IMethodPolicy;
use router\interface\IRequest;
use router\interface\IRouteResolver;

RouteResolver

Declaration and architectural role

final class RouteResolver implements IRouteResolver

Constants, enum cases, traits and properties

Declarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.

Member Declaration Purpose or source contract
Constructor-promoted public function __construct(private readonly IMethodPolicy $methods = new HttpMethod()) Initialized from the constructor argument; default expression is evaluated when the argument is omitted.

Method index

Method Signature
__construct public function __construct(private readonly IMethodPolicy $methods = new HttpMethod())
resolve public function resolve(array $routes, IRequest $request): RouteResolution

__construct

Source line 12

public function __construct(private readonly IMethodPolicy $methods = new HttpMethod());

Parameters

Parameter Type, modifiers and default Purpose
$methods private readonly IMethodPolicy $methods = new HttpMethod() Operation input; the exact use, validation and propagation are shown in the implementation trace.

Concrete no-op/default hook: this method performs no work. Override it where the lifecycle or extension contract calls for behavior.

resolve

Source line 14

public function resolve(array $routes, IRequest $request): RouteResolution

Parameters

Parameter Type, modifiers and default Purpose
$routes array $routes Operation input; the exact use, validation and propagation are shown in the implementation trace.
$request IRequest $request Request snapshot consumed by matching, method and security checks.

Return expressions (including local callbacks): new RouteResolution($route, $params); $fallback ?? new RouteResolution(allowed: array_values(array_unique($allowed))).

Implementation, validation guards and interaction order
public function resolve(array $routes, IRequest $request): RouteResolution
    {
        $allowed = [];
        $fallback = null;
        foreach ($routes as $route) {
            $params = $route->match($request->path());
            if ($params === null) {
                continue;
            }
            $allowed = array_merge($allowed, $this->methods->allowed($route->getMethod()));
            if ($route->getMethod() === $request->method()) {
                return new RouteResolution($route, $params);
            }
            if ($this->methods->allows($route->getMethod(), $request->method())) {
                $fallback ??= new RouteResolution($route, $params);
            }
        }
        return $fallback ?? new RouteResolution(allowed: array_values(array_unique($allowed)));
    }

Related types

Clone this wiki locally