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
| Name | Type | Description |
|---|---|---|
| $path | string | |
| $methods | (HttpMethod | non-empty-list<HttpMethod>) | one verb, or a list of verbs |
| $name | ?string | |
| $middleware | list<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): selfA `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
| Name | Type | Description |
|---|---|---|
| $path | string | |
| $handler | array<mixed> | |
| $name | ?string |
Route::post()
public static function post(string $path, array $handler, ?string $name = null): selfA `POST` route — the handler is named as in {@see self::get()}.
Parameters
| Name | Type | Description |
|---|---|---|
| $path | string | |
| $handler | array<mixed> | |
| $name | ?string |
Route::behind()
public static function behind(array $middleware, self ...$routes): arrayThe 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
| Name | Type | Description |
|---|---|---|
| $middleware | list<class-string> | |
| $routes | self |
Route::withMiddleware()
public function withMiddleware(array $middleware): selfReturn a copy carrying the given per-route middleware, outermost first.
Parameters
| Name | Type | Description |
|---|---|---|
| $middleware | list<class-string> |
Route::withHandler()
public function withHandler(Milpa\Http\Routing\HandlerReference $handler): selfBind the handler discovered by attribute reflection, returning a new instance.
Parameters
| Name | Type | Description |
|---|---|---|
| $handler | Milpa\Http\Routing\HandlerReference |
Route::withName()
public function withName(string $name): selfReturn a copy carrying the given route name.
Parameters
| Name | Type | Description |
|---|---|---|
| $name | string |
Route::allows()
public function allows(Milpa\Http\HttpMethod $method): boolWhether this route accepts the given HTTP method.
Parameters
| Name | Type | Description |
|---|---|---|
| $method | Milpa\Http\HttpMethod |
Route::isBound()
public function isBound(): boolWhether the handler has been bound (never null once the kernel has processed the route).