Group
Group
Route grouping helper that applies a shared URL prefix and cross-cutting behavior.
class Group implements \Hazaar\Application\Interface\Route , \Hazaar\Application\Interface\RouterImplements: Hazaar\Application\Interface\Route, Hazaar\Application\Interface\Router
A group is a lightweight facade around the main Hazaar\Application\Router that:
- prefixes route paths with a common base segment,
- tracks routes and nested groups created within the scope,
- supports bulk middleware and authentication application across the group,
- allows hierarchical grouping through nested prefixes.
Routes registered via HTTP verb helpers are delegated to the underlying router, while the group retains references so later operations such as Hazaar\Application\Router\Group::middleware and Hazaar\Application\Router\Group::auth can be applied consistently.
Properties
router
Parent router responsible for final route registration and dispatch.
private Router $routerType: Hazaar\Application\Router
prefix
Normalized URL prefix applied to all routes defined in this group.
private string $prefixType: string
The prefix always starts with a single /.
routes
private array $routesType: array
Methods
__construct
Creates a route group bound to a parent router and URL prefix.
public __construct(Router $router, string $prefix): voidParameters
| Parameter | Type | Description |
|---|---|---|
$router | Hazaar\Application\Router | the parent router used to register concrete routes |
$prefix | string | group prefix that will be normalized to start with / |
middleware
Applies a middleware to the route group.
public middleware(Middleware|string $middleware, mixed $args): selfReturns: self
This method iterates over all routes currently registered in the group and applies the specified middleware to each of them.
Parameters
| Parameter | Type | Description |
|---|---|---|
$middleware | Hazaar\Middleware\Interface\Middleware | string |
$args | mixed |
addRoute
Adds a route to the group.
public addRoute(Route $route): voidReturns: void
This method adds a route instance to the group's internal list of routes. It also applies the group's path prefix to the route and registers the route with the main router.
Parameters
| Parameter | Type | Description |
|---|---|---|
$route | Hazaar\Application\Route | the route instance to add to the group |
get
Registers a route that responds to HTTP GET requests.
public get(string $path, \Closure|\ReflectionMethod|array|string $callable, array $actionArgs): RouteReturns: Hazaar\Application\Route
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the URL path for the route |
$callable | Closure | ReflectionMethod |
$actionArgs | array | optional action arguments for the route |
post
Registers a route that responds to HTTP POST requests.
public post(string $path, \Closure|\ReflectionMethod|array|string $callable, array $actionArgs): RouteReturns: Hazaar\Application\Route
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the URL path for the route |
$callable | Closure | ReflectionMethod |
$actionArgs | array | optional action arguments for the route |
put
Registers a route that responds to HTTP PUT requests.
public put(string $path, \Closure|\ReflectionMethod|array|string $callable, array $actionArgs): RouteReturns: Hazaar\Application\Route
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the URI path that the route will respond to |
$callable | Closure | ReflectionMethod |
$actionArgs | array | optional action arguments for the route |
delete
Registers a route that responds to HTTP DELETE requests.
public delete(string $path, \Closure|\ReflectionMethod|array|string $callable, array $actionArgs): RouteReturns: Hazaar\Application\Route
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the URL path that the route should match |
$callable | Closure | ReflectionMethod |
$actionArgs | array | optional action arguments for the route |
patch
Registers a route that responds to HTTP PATCH requests.
public patch(string $path, \Closure|\ReflectionMethod|array|string $callable, array $actionArgs): RouteReturns: Hazaar\Application\Route
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the URI path that the route will match |
$callable | Closure | ReflectionMethod |
$actionArgs | array | optional action arguments for the route |
options
Registers a route that responds to HTTP OPTIONS requests.
public options(string $path, \Closure|\ReflectionMethod|array|string $callable, array $actionArgs): RouteReturns: Hazaar\Application\Route
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the URL path to match |
$callable | Closure | ReflectionMethod |
$actionArgs | array | optional action arguments for the route |
any
Registers a route that responds to any HTTP method.
public any(string $path, \Closure|\ReflectionMethod|array|string $callable, array $actionArgs): RouteReturns: Hazaar\Application\Route
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | the path pattern to match |
$callable | Closure | ReflectionMethod |
$actionArgs | array | optional action arguments for the route |
group
Groups routes under a common URL prefix.
public group(string $prefix, \Closure $callback): GroupReturns: Hazaar\Application\Router\Group
This 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 (array|string|null $methods, string $path, \Closure|\ReflectionMethod|array|string $callable, array $actionArgs): RouteReturns: Hazaar\Application\Route
Parameters
| Parameter | Type | Description |
|---|---|---|
$methods | array | string |
$path | string | The path to match (e.g., '/user/{id}'). |
$callable | Closure | ReflectionMethod |
$actionArgs | array | optional action arguments for the route |
auth
Applies authentication to all routes within the group.
public auth(?Adapter $adapter, mixed $args): RouteInterfaceReturns: Hazaar\Application\Interface\Route
If an authentication adapter is provided, it will be used for all routes. Otherwise, the default adapter will be used.
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): RouteInterfaceReturns: Hazaar\Application\Interface\Route
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 |
getPath
Get the full path for the route group, optionally appending a suffix.
private getPath(?string $suffix): stringReturns: string
This method combines the group's prefix with a provided suffix to form a complete path. If no suffix is provided, it returns the prefix alone. It ensures that there are no double slashes where the prefix and suffix join.
Parameters
| Parameter | Type | Description |
|---|---|---|
$suffix | string | An optional path segment to append to the group prefix. Any leading slashes will be trimmed. |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000