Skip to content
docsv0.5.0

Router

The family's reference {@see RouterInterface} implementation: exact path segments plus single-segment `{placeholder}` parameters. Never throws, never returns null — a {@see RouteResult} always carries the outcome, exactly as the contract demands. A trailing slash is normalized away before matching (`/posts/` and `/posts` are the same route), and the root path always matches as `/`. Route order matters for the `Allow` header on a method miss: every route whose path matches the request, regardless of method, contributes its verbs to the eventual {@see MatchStatus::METHOD_NOT_ALLOWED} result.

Router::__construct()

public function __construct(Milpa\Http\Routing\Route ...$routes):

Parameters

Parameters of __construct()
NameTypeDescription
$routesRoutethe route table, in match priority order

Router::routes()

public function routes(): array

The route table this router matches against, in the order it was given. Reverse routing needs to READ the table, and until this existed the table was reachable by nobody: the Kernel builds it, hands it to this constructor, and the only public method was {@see self::match()}. Additive and read-only — the array is already `readonly`, and a caller gets the same immutable value objects the matcher uses, so there is no second table to drift (greenhouse decisions/0215, F4).

Router::match()

public function match(Psr\Http\Message\ServerRequestInterface $request): Milpa\Http\Routing\RouteResult

Resolves the request to a typed result — always MATCHED, NOT_FOUND or METHOD_NOT_ALLOWED, never null.

Parameters

Parameters of match()
NameTypeDescription
$requestPsr\Http\Message\ServerRequestInterface