RouteBuilder
in package
Fluent per-route configuration builder returned by HTTP verb methods.
RouteBuilder is the object you receive after calling
$app->get(...), $app->post(...), etc. It lets you chain per-route
settings — middleware and a named route identifier — before
HttpApp::compile() freezes the builder into an immutable
Route value object that drives the dispatcher.
The builder is intentionally mutable; the terminal compile() call on
HttpApp converts all pending builders atomically and nothing else holds
a reference to the builder after that point.
Example — adding per-route middleware and a name:
$app->post('/users', UserHandler::class)
->middleware(AuthenticationMiddleware::class)
->middleware(RateLimitMiddleware::class)
->name('user.create');
Tags
Table of Contents
Methods
- __construct() : mixed
- build() : Route
- Freeze this builder into an immutable Route value object.
- middleware() : self
- Append a PSR-15 middleware class name to this route's middleware chain.
- name() : self
- Assign a human-readable name to this route for reverse routing and logging.
Methods
__construct()
public
__construct(string $method, string $path, string|Closure $handler) : mixed
Parameters
- $method : string
- $path : string
- $handler : string|Closure
build()
Freeze this builder into an immutable Route value object.
public
build() : Route
Called internally by HttpApp::compile(); application code should not need to call this directly.
Return values
Routemiddleware()
Append a PSR-15 middleware class name to this route's middleware chain.
public
middleware(string $class) : self
Route middleware runs after global middleware and before the handler. Multiple calls append in order.
Parameters
- $class : string
-
Fully-qualified class name of the PSR-15 middleware.
Return values
selfname()
Assign a human-readable name to this route for reverse routing and logging.
public
name(string $name) : self
Parameters
- $name : string
-
Unique route name within the application.