Skip to content
docsv0.1.0

RouteResult

The immutable, never-null outcome of {@see RouterInterface::match()} — and the only value routing injects into the request. A success carries the matched {@see Route} plus the extracted path arguments; a method failure carries the verbs the path does allow (for the `Allow` header); a miss carries nothing. Built only through the three named constructors, so illegal states (a match with no route, a 405 with no verbs) are unrepresentable.

RouteResult::matched()

public static function matched(Milpa\Http\Routing\Route $route, array $parameters = []): self

A successful match: the route and its extracted path arguments.

Parameters

Parameters of matched()
NameTypeDescription
$routeMilpa\Http\Routing\Route
$parametersarray<string, string>

RouteResult::notFound()

public static function notFound(): self

No route matched the path (→ 404).

RouteResult::methodNotAllowed()

public static function methodNotAllowed(array $allowedMethods): self

The path matched but the method did not (→ 405); carries the allowed verbs.

Parameters

Parameters of methodNotAllowed()
NameTypeDescription
$allowedMethodsnon-empty-list<HttpMethod>

RouteResult::isMatched()

public function isMatched(): bool

Whether a route was matched.

RouteResult::parameter()

public function parameter(string $name, ?string $default = null): ?string

Read a single extracted path parameter, or the default when it is absent.

Parameters

Parameters of parameter()
NameTypeDescription
$namestring
$default?string