Router
Router
Properties
defaultConfig
Default configuration.
public array $defaultConfig = array (
'controller' => 'index',
'action' => 'index',
'args' =>
array (
),
)internal
Internal controllers.
public array $internal = array (
'hazaar' => '\\Hazaar\\Controller\\Internal',
)config
public array $configrouteLoader
private Loader $routeLoadermiddlewareDispatcher
private Dispatcher $middlewareDispatcherroutes
private array $routesinstance
public self $instanceMethods
__construct
public __construct(array $config, array $middlewareAliases): voidParameters
| Parameter | Type | Description |
|---|---|---|
$config | array | |
$middlewareAliases | array |
getInstance
Get the current router instance.
public getInstance(): ?selfThis method retrieves the singleton instance of the Router from the main Application.
setInstance
Sets the global instance of the Router.
public setInstance(self $router): voidThis method allows setting the singleton instance of the Router class. It is typically used by router loaders that require a global router instance accessible through the Router class.
Parameters
| Parameter | Type | Description |
|---|---|---|
$router | self | the router instance to set as the global instance |
clearInstance
Clears the current Singleton instance.
public clearInstance(): voidThis method resets the static instance variable to null, effectively clearing the current instance of the class. It is typically used by router loaders that require a global router instance accessible through the Router class.
initialise
public initialise(): boolhandle
Handles an incoming HTTP request by evaluating the route, applying middleware, and executing the controller logic.
public handle(Request $request): RouteParameters
| Parameter | Type | Description |
|---|---|---|
$request | Request | the incoming HTTP request to handle |
addRoute
Adds a route to the router.
public addRoute(Route $route): voidThis method sets the router for the given route and then adds the route to the list of routes managed by this router.
Parameters
| Parameter | Type | Description |
|---|---|---|
$route | Route | the route to be added |
add
Adds a route to the router.
public add(Route $route): voidThis method is a static convenience wrapper that adds a new route instance to the singleton instance of the Router.
Parameters
| Parameter | Type | Description |
|---|---|---|
$route | Route | the route object to add |
getErrorController
Retrieves the error controller instance.
public getErrorController(): ErrorThis method checks the configuration for a specified error controller class. If the class exists and is a subclass of the Error class, it instantiates and returns the error controller. If no valid error controller is found in the configuration, it returns a default Error instance.
get
Registers a route that responds to HTTP GET requests.
public get(string $path, mixed $callable, array $actionArgs): RouteParameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the URL path for the route |
$callable | mixed | the callback or controller action to handle the request |
$actionArgs | array | optional action arguments for the route |
post
Registers a route that responds to HTTP POST requests.
public post(string $path, mixed $callable, array $actionArgs): RouteParameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the URL path for the route |
$callable | mixed | the callback or controller method to handle the request |
$actionArgs | array | optional action arguments for the route |
put
Registers a route that responds to HTTP PUT requests.
public put(string $path, mixed $callable, array $actionArgs): RouteParameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the URI path that the route will respond to |
$callable | mixed | the handler for the route, which can be a callable or other valid route handler |
$actionArgs | array | optional action arguments for the route |
delete
Registers a route that responds to HTTP DELETE requests.
public delete(string $path, mixed $callable, array $actionArgs): RouteParameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the URL path that the route should match |
$callable | mixed | the callback or controller action to be executed when the route is matched |
$actionArgs | array | optional action arguments for the route |
patch
Registers a route that responds to HTTP PATCH requests.
public patch(string $path, mixed $callable, array $actionArgs): RouteParameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the URI path that the route will match |
$callable | mixed | the callback or controller action to be executed when the route is matched |
$actionArgs | array | optional action arguments for the route |
options
Registers a route that responds to HTTP OPTIONS requests.
public options(string $path, mixed $callable, array $actionArgs): RouteParameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the URL path to match |
$callable | mixed | the callback or controller action to handle the request |
$actionArgs | array | optional action arguments for the route |
any
Registers a route that responds to any HTTP method.
public any(string $path, mixed $callable, array $actionArgs): RouteParameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the path pattern to match |
$callable | mixed | the callback to execute when the route is matched |
$actionArgs | array | optional action arguments for the route |
group
Groups routes under a common URL prefix.
public group(string $prefix, \Closure $callback): GroupThis method allows you to group multiple route definitions that share a common URL path prefix. The provided callback function will be executed with the router instance, allowing routes defined within to inherit the prefix logic (though currently the prefix appears unused in this implementation).
Parameters
| Parameter | Type | Description |
|---|---|---|
$prefix | string | the URL prefix for the grouped routes |
$callback | \Closure | a callback function that receives the Router instance |
Matches a route with the given HTTP methods, path, and callable.
public (null $methods, string $path, mixed $callable, array $actionArgs): RouteParameters
| Parameter | Type | Description |
|---|---|---|
$methods | null | The HTTP methods to match (e.g., ['GET', 'POST']). |
$path | string | The path to match (e.g., '/user/{id}'). |
$callable | mixed | The callable to execute when the route is matched. It can be a string in the format 'Class::method', an array with the class and method, or a Closure. |
$actionArgs | array | optional action arguments for the route |
matchRoute
Matches a route with the given HTTP methods, path, and callable.
public matchRoute(null $methods, string $path, mixed $callable, array $actionArgs): RouteParameters
| Parameter | Type | Description |
|---|---|---|
$methods | null | The HTTP methods to match (e.g., ['GET', 'POST']). |
$path | string | The path to match (e.g., '/user/{id}'). |
$callable | mixed | The callable to execute when the route is matched. It can be a string in the format 'Class::method', an array with the class and method, or a Closure. |
$actionArgs | array | optional action arguments for the route |
evaluateRequest
Evaluates the given request and matches it against the defined routes.
public evaluateRequest(Request $request): ?RouteParameters
| Parameter | Type | Description |
|---|---|---|
$request | Request | the request to evaluate |
Generated by Hazaar API Doc Generator on Sun, 01 Mar 2026 09:22:26 +0000