Group
Group
Route grouping helper that applies a shared URL prefix and cross-cutting behavior.
class Group implements \Hazaar\Application\Router\RouteInterface , \Hazaar\Application\Router\RouterInterfaceA group is a lightweight facade around the main {@see 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 {@see self
Properties
router
Parent router responsible for final route registration and dispatch.
private Router $routerprefix
Normalized URL prefix applied to all routes defined in this group.
private string $prefixThe prefix always starts with a single /.
routes
private array $routesMethods
__construct
Creates a route group bound to a parent router and URL prefix.
public __construct(Router $router, string $prefix): voidParameters
| Parameter | Type | Description |
|---|---|---|
$router | 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(string $middleware, mixed $args): selfThis method iterates over all routes currently registered in the group and applies the specified middleware to each of them.
Parameters
| Parameter | Type | Description |
|---|---|---|
$middleware | string | the middleware to apply, either as a string or an instance |
$args | mixed |
addRoute
Adds a route to the group.
public addRoute(Route $route): voidThis 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 | Route | the route instance to add to the group |
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 |
auth
Applies authentication to all routes within the group.
public auth(?Adapter $adapter, mixed $args): RouteInterfaceIf an authentication adapter is provided, it will be used for all routes. Otherwise, the default adapter will be used.
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): RouteInterfaceThis 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): stringThis 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 Tue, 21 Apr 2026 04:00:25 +0000