Skip to content
docsv0.1.0

Route

The one canonical route: the same immutable type you declare with `#[Route(...)]` on a controller method AND the value a matcher returns inside a {@see RouteResult}. It holds only static route facts — path, verbs, name, host, priority, defaults and per-route middleware; per-request path arguments live on the RouteResult. The `handler` is null only between declaration (an attribute cannot name its own method as a constant expression) and binding: the kernel calls {@see self::withHandler()} once reflection supplies the controller and method. Assert it with {@see self::isBound()}.

Route::__construct()

public function __construct(string $path, Milpa\Http\HttpMethod|array $methods = Milpa\Http\HttpMethod::GET, ?string $name = null, ?string $host = null, int $priority = 0, array $defaults = [], array $middleware = [], ?Milpa\Http\Routing\HandlerReference $handler = null):

Parameters

Parameters of __construct()
NameTypeDescription
$pathstring
$methods(HttpMethod | non-empty-list<HttpMethod>)one verb, or a list of verbs
$name?string
$host?string
$priorityint
$defaultsarray<string, string>default values for optional path params
$middlewarelist<class-string>per-route PSR-15 middleware (kernel resolves via PSR-11)
$handler?Milpa\Http\Routing\HandlerReference

Route::withHandler()

public function withHandler(Milpa\Http\Routing\HandlerReference $handler): self

Bind the handler discovered by attribute reflection, returning a new instance.

Parameters

Parameters of withHandler()
NameTypeDescription
$handlerMilpa\Http\Routing\HandlerReference

Route::withName()

public function withName(string $name): self

Return a copy carrying the given route name.

Parameters

Parameters of withName()
NameTypeDescription
$namestring

Route::allows()

public function allows(Milpa\Http\HttpMethod $method): bool

Whether this route accepts the given HTTP method.

Parameters

Parameters of allows()
NameTypeDescription
$methodMilpa\Http\HttpMethod

Route::isBound()

public function isBound(): bool

Whether the handler has been bound (never null once the kernel has processed the route).