Route
Route
class Route implements \Hazaar\Application\Properties
router
Router instance that owns this route and provides fallback configuration.
public Router $routercallable
Route target callable.
private mixed $callableAccepted forms include closures, [ControllerClass, method] arrays, and reflected methods.
path
public string $pathresponseType
Response type inferred from callable return type metadata.
private ResponseType $responseType = 'ResponseType'methods
private array $methodsactionArgs
private array $actionArgscallableParameters
private array $callableParametersmiddleware
private array $middlewareMethods
__construct
public __construct(?string $path, array $methods): voidParameters
| Parameter | Type | Description |
|---|---|---|
$path | string | |
$methods | array |
setCallable
Sets the callable for the route and processes its reflection.
public setCallable(mixed $callable): voidParameters
| Parameter | Type | Description |
|---|---|---|
$callable | mixed | The callable to be set. It can be a closure, an array with a class and method, or a reflection method. |
setActionArgs
Sets the arguments for the route action.
public setActionArgs(array $actionArgs): voidParameters
| Parameter | Type | Description |
|---|---|---|
$actionArgs | array | an array of default arguments to be passed to the route action |
setRouter
Sets the router instance for the application.
public setRouter(Router $router): voidParameters
| Parameter | Type | Description |
|---|---|---|
$router | Router | the router instance to be set |
getPath
Retrieves the path associated with the current route.
public getPath(): ?stringMatches the given HTTP method and path against the route's method and path.
public (string $method, string $path): boolParameters
| Parameter | Type | Description |
|---|---|---|
$method | string | The HTTP method to match (e.g., 'GET', 'POST'). |
$path | string | the request path to match |
getControllerClass
Returns the controller class resolved from the current callable.
public getControllerClass(): ?stringgetControllerName
Returns the lowercase short controller name.
public getControllerName(): stringThis derives the basename from {@see self::getControllerClass()} and lowercases it.
getController
Retrieves the controller instance based on the callable property.
public getController(Request $request): ?ControllerThis method checks if the callable property is a Closure or an array. If it is a Closure, it returns a new Closure instance. If it is an array, it extracts the controller class name, verifies its existence, and returns a new instance of the controller class.
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | Request |
getAction
Retrieves the action to be executed.
public getAction(): stringThis method checks if the action is defined in the callable array. If it is, it returns that action. Otherwise, it falls back to the default action specified in the router configuration.
getActionArgs
Retrieve the action arguments.
public getActionArgs(): voidThis method returns an array of arguments that are passed to the action.
getResponseType
Retrieves the response type of the route.
public getResponseType(): ResponseTypegetMiddleware
Get the names of all middleware associated with the route.
public getMiddleware(): voidprefixPath
Prefixes the path of the route with the given path.
public prefixPath(string $path): voidParameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the path to be prefixed |
middleware
Adds middleware(s) to the route.
public middleware(string $middleware, mixed $args): selfAccepts a string of middleware names separated by colons and merges them into the existing middleware array.
Parameters
| Parameter | Type | Description |
|---|---|---|
$middleware | string | the middleware to add, either as a string or an instance |
$args | mixed |
getMiddlewareHandlers
Retrieves the list of middleware associated with the route.
public getMiddlewareHandlers(): voidauth
Adds authentication middleware to the route.
public auth(?Adapter $adapter, mixed $args): selfThis method initializes the authentication middleware stack using session, cookie, and JWT mechanisms, and attaches it to the route. Optionally, a custom authentication adapter and additional arguments can be provided.
Parameters
| Parameter | Type | Description |
|---|---|---|
$adapter | Adapter | optional authentication adapter to use |
$args | mixed |
session
Initializes session handling middleware for the route.
public session(mixed $args): selfThis method will add session middleware to the route, allowing a session to be created but without requiring authentication. Any additional arguments can be passed to customize the session handling behavior.
Parameters
| Parameter | Type | Description |
|---|---|---|
$args | mixed |
ratelimit
Adds a rate limiting middleware to the route.
public ratelimit(int $requests, int $seconds): selfLimits the number of requests that can be made to this route within a specified time window. This is a helper that will use the defaults for the selected RateLimiter backend, which is cache-based by default. For more advanced usage, you can directly add a Ratelimiter middleware with custom options using the middleware() method.
Parameters
| Parameter | Type | Description |
|---|---|---|
$requests | int | the maximum number of allowed requests within the time window |
$seconds | int | the time window in seconds for the rate limit |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:25 +0000