Skip to content
docsv0.5.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, array $middleware = [], ?Milpa\Http\Routing\HandlerReference $handler = null):

`$host`, `$priority` and `$defaults` used to sit here and were removed: the matcher never read one of them, so they were three promises this package did not keep — and a declaration a reader can set and nothing obeys is worse than an absent feature, because it looks like a feature (greenhouse decisions/0213 row 5, decisions/0215). Whoever wants host matching or an explicit priority proposes them WITH the matcher that honours them.

Parameters

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

Route::get()

public static function get(string $path, array $handler, ?string $name = null): self

A `GET` route, its handler named the way a controller is named: `[Controller::class, 'method']`. The constructor stays the canon; this produces the same value with the verb said once, as the method name, and the reference derived from the pair ({@see HandlerReference::of()}, greenhouse decisions/0388). Only the verbs with a consumer in the family exist here — `put`/`patch`/`delete` arrive with their first caller.

Parameters

Parameters of get()
NameTypeDescription
$pathstring
$handlerarray<mixed>
$name?string

Route::post()

public static function post(string $path, array $handler, ?string $name = null): self

A `POST` route — the handler is named as in {@see self::get()}.

Parameters

Parameters of post()
NameTypeDescription
$pathstring
$handlerarray<mixed>
$name?string

Route::behind()

public static function behind(array $middleware, self ...$routes): array

The same routes, each behind one door: the given middleware is prepended — outermost, the position the constructor's list gives it — to whatever each route already carries, so a provider declares its gate once for the group instead of once per route. Keys are not preserved: the argument is a list.

Parameters

Parameters of behind()
NameTypeDescription
$middlewarelist<class-string>
$routesself

Route::withMiddleware()

public function withMiddleware(array $middleware): self

Return a copy carrying the given per-route middleware, outermost first.

Parameters

Parameters of withMiddleware()
NameTypeDescription
$middlewarelist<class-string>

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).