Route
Route
class Route implements \Hazaar\Application\Interface\RouteImplements: Hazaar\Application\Interface\Route
Properties
router
Router instance that owns this route and provides fallback configuration.
public Router $routerType: Hazaar\Application\Router
callable
Route target callable.
private \Closure|\ReflectionMethod|array|string $callableType: Closure|ReflectionMethod|array|string
Accepted forms include closures, [ControllerClass, method] arrays, and reflected methods.
path
public string $pathType: string
responseType
Response type inferred from callable return type metadata.
private ResponseType $responseType = 'ResponseType'Type: Hazaar\Controller\Enums\ResponseType
methods
private array $methodsType: array
actionArgs
private array $actionArgsType: array
callableParameters
private array $callableParametersType: array
middleware
private array $middlewareType: array
Methods
__construct
public __construct(?string $path, array|string|null $methods): voidParameters
| Parameter | Type | Description |
|---|---|---|
$path | string | |
$methods | array | string |
setCallable
Sets the callable for the route and processes its reflection.
public setCallable(\Closure|\ReflectionMethod|array|string $callable): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$callable | Closure | ReflectionMethod |
setActionArgs
Sets the arguments for the route action.
public setActionArgs(array $actionArgs): voidReturns: void
Parameters
| 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): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$router | Hazaar\Application\Router | the router instance to be set |
getPath
Retrieves the path associated with the current route.
public getPath(): ?stringReturns: string
getMethods
Retrieves the HTTP methods this route matches.
public getMethods(): arrayReturns: array
Matches the given HTTP method and path against the route's method and path.
public (string $method, string $path): boolReturns: bool
Parameters
| 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(): ?stringReturns: string
getControllerName
Returns the lowercase short controller name.
public getControllerName(): stringReturns: string
This derives the basename from Hazaar\Application\Route::getControllerClass and lowercases it.
getController
Retrieves the controller instance based on the callable property.
public getController(Request $request): ?ControllerReturns: Hazaar\Controller
This 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 | Hazaar\Application\Request |
getAction
Retrieves the action to be executed.
public getAction(): stringReturns: string
This 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(): arrayReturns: array
This method returns an array of arguments that are passed to the action.
getResponseType
Retrieves the response type of the route.
public getResponseType(): ResponseTypeReturns: Hazaar\Controller\Enums\ResponseType
getMiddleware
Get the names of all middleware associated with the route.
public getMiddleware(): arrayReturns: array
prefixPath
Prefixes the path of the route with the given path.
public prefixPath(string $path): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the path to be prefixed |
middleware
Adds middleware(s) to the route.
public middleware(Middleware|string $middleware, mixed $args): selfReturns: self
Accepts a string of middleware names separated by colons and merges them into the existing middleware array.
Parameters
| Parameter | Type | Description |
|---|---|---|
$middleware | Hazaar\Middleware\Interface\Middleware | string |
$args | mixed |
getMiddlewareHandlers
Retrieves the list of middleware associated with the route.
public getMiddlewareHandlers(): arrayReturns: array
auth
Adds authentication middleware to the route.
public auth(?Adapter $adapter, mixed $args): selfReturns: self
This 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 | Hazaar\Auth\Adapter | optional authentication adapter to use |
$args | mixed |
session
Initializes session handling middleware for the route.
public session(mixed $args): selfReturns: self
This 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): selfReturns: self
Limits 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 Fri, 04 Sep 2026 23:32:17 +0000