API Index — Namespaces, Packages, Reports, Indices
RouteGroup
in package
Route group — the object handed to an App::group() callback. It mirrors the
App route registrars (route / nsRoute / nsPathRoute / patternRoute)
and nested group(), transparently:
- prepending the group's URL prefix to each route's path, and
- prepending the group's shared middleware chain (outermost) to each route's own middleware.
$app->group('/admin', ['auth', 'admin-only'], function ($g) {
$g->route('/users', fn() => User::all());
$g->route('/settings', fn() => Settings::get());
$g->group('/audit', ['audit-log'], function ($g) { // nests: /admin/audit/*
$g->route('/recent', fn() => Audit::recent()); // auth → admin-only → audit-log → handler
});
});
Ordering: group middleware wraps outside a route's own middleware, which wraps outside the handler — same first-listed-is-outermost rule as the global stack. Groups nest: an inner group composes its prefix and middleware onto the outer group's.
Stateless-middleware contract still applies: a middleware instance (or alias)
named here is shared across every concurrent request that route serves, so it
must keep per-request state in $g (RequestContext), never on itself.
Table of Contents
Properties
- $app : App
- $middleware : array<string|int, mixed>
- $prefix : string
Methods
- __construct() : mixed
- any() : void
- delete() : void
- get() : void
- group() : void
- Nested group — composes this group's prefix + middleware onto a child.
- nsPathRoute() : void
- nsRoute() : void
- options() : void
- patch() : void
- patternRoute() : void
- Pattern routes carry a raw, user-authored regex, so the group **prefix is NOT auto-applied** (prefixing an arbitrary regex is ambiguous — bake the prefix into your pattern). The group **middleware IS** still applied.
- post() : void
- put() : void
- route() : void
- combine() : array<int, MiddlewareInterface|string>
- Group prefix + middleware ++ the route's own (options then named arg).
- joinPath() : string
- Join the group prefix to a child path (or nested-group prefix), collapsing
the boundary slash so a trailing-slash prefix never produces a double slash
(#308).
group('/admin/')->route('/users')→/admin/users, not the unreachable/admin//users. An empty path yields the bare prefix; a missing leading slash on the path is also normalised (route('users')works). -
normalizeShorthand()
: array{0: array
, 1: callable|array |null} - Apply the "second arg is the handler" shorthand (
$g->route('/x', $fn)). - prefixNamespace() : string
- stripMiddleware() : array<string, mixed>
Properties
$app
private
App
$app
$middleware
private
array<string|int, mixed>
$middleware
= []
$prefix
private
string
$prefix
Methods
__construct()
public
__construct(App $app, string $prefix[, array<int, MiddlewareInterface|string> $middleware = [] ]) : mixed
Parameters
- $app : App
- $prefix : string
- $middleware : array<int, MiddlewareInterface|string> = []
-
Group-level chain, already normalized.
any()
public
any(string $path, callable|array<int|string, mixed> $handler[, array<string, mixed> $options = [] ][, bool $raw = false ][, array<int, MiddlewareInterface|string> $middleware = [] ][, array<string, mixed>|string|null $backend = null ]) : void
Parameters
- $path : string
- $handler : callable|array<int|string, mixed>
- $options : array<string, mixed> = []
- $raw : bool = false
- $middleware : array<int, MiddlewareInterface|string> = []
- $backend : array<string, mixed>|string|null = null
delete()
public
delete(string $path, callable|array<int|string, mixed> $handler[, array<string, mixed> $options = [] ][, bool $raw = false ][, array<int, MiddlewareInterface|string> $middleware = [] ][, array<string, mixed>|string|null $backend = null ]) : void
Parameters
- $path : string
- $handler : callable|array<int|string, mixed>
- $options : array<string, mixed> = []
- $raw : bool = false
- $middleware : array<int, MiddlewareInterface|string> = []
- $backend : array<string, mixed>|string|null = null
get()
public
get(string $path, callable|array<int|string, mixed> $handler[, array<string, mixed> $options = [] ][, bool $raw = false ][, array<int, MiddlewareInterface|string> $middleware = [] ][, array<string, mixed>|string|null $backend = null ]) : void
Parameters
- $path : string
- $handler : callable|array<int|string, mixed>
- $options : array<string, mixed> = []
- $raw : bool = false
- $middleware : array<int, MiddlewareInterface|string> = []
- $backend : array<string, mixed>|string|null = null
group()
Nested group — composes this group's prefix + middleware onto a child.
public
group(string $prefix[, array<int, MiddlewareInterface|string>|callable $middleware = [] ][, callable|null $registrar = null ]) : void
Parameters
- $prefix : string
- $middleware : array<int, MiddlewareInterface|string>|callable = []
- $registrar : callable|null = null
nsPathRoute()
public
nsPathRoute(string $namespace, string $path[, array<string, mixed>|callable $options = [] ][, callable|null $handler = null ][, array<int, string> $methods = [] ][, bool $raw = false ][, array<int, MiddlewareInterface|string> $middleware = [] ][, array<string, mixed>|string|null $backend = null ]) : void
Parameters
- $namespace : string
- $path : string
- $options : array<string, mixed>|callable = []
- $handler : callable|null = null
- $methods : array<int, string> = []
- $raw : bool = false
- $middleware : array<int, MiddlewareInterface|string> = []
- $backend : array<string, mixed>|string|null = null
-
Per-route CGI backend (bare mode /
App::cgiBackendAlias()name / inline config); delegated toApp::nsPathRoute().
nsRoute()
public
nsRoute(string $namespace, string $path[, array<string, mixed>|callable $options = [] ][, callable|null $handler = null ][, array<int, string> $methods = [] ][, bool $raw = false ][, array<int, MiddlewareInterface|string> $middleware = [] ][, array<string, mixed>|string|null $backend = null ]) : void
Parameters
- $namespace : string
- $path : string
- $options : array<string, mixed>|callable = []
- $handler : callable|null = null
- $methods : array<int, string> = []
- $raw : bool = false
- $middleware : array<int, MiddlewareInterface|string> = []
- $backend : array<string, mixed>|string|null = null
-
Per-route CGI backend (bare mode /
App::cgiBackendAlias()name / inline config); delegated toApp::nsRoute().
options()
public
options(string $path, callable|array<int|string, mixed> $handler[, array<string, mixed> $options = [] ][, bool $raw = false ][, array<int, MiddlewareInterface|string> $middleware = [] ][, array<string, mixed>|string|null $backend = null ]) : void
Parameters
- $path : string
- $handler : callable|array<int|string, mixed>
- $options : array<string, mixed> = []
- $raw : bool = false
- $middleware : array<int, MiddlewareInterface|string> = []
- $backend : array<string, mixed>|string|null = null
patch()
public
patch(string $path, callable|array<int|string, mixed> $handler[, array<string, mixed> $options = [] ][, bool $raw = false ][, array<int, MiddlewareInterface|string> $middleware = [] ][, array<string, mixed>|string|null $backend = null ]) : void
Parameters
- $path : string
- $handler : callable|array<int|string, mixed>
- $options : array<string, mixed> = []
- $raw : bool = false
- $middleware : array<int, MiddlewareInterface|string> = []
- $backend : array<string, mixed>|string|null = null
patternRoute()
Pattern routes carry a raw, user-authored regex, so the group **prefix is NOT auto-applied** (prefixing an arbitrary regex is ambiguous — bake the prefix into your pattern). The group **middleware IS** still applied.
public
patternRoute(string $regex[, array<string, mixed>|callable $options = [] ][, callable|null $handler = null ][, array<int, string> $methods = [] ][, bool $raw = false ][, array<int, MiddlewareInterface|string> $middleware = [] ][, array<string, mixed>|string|null $backend = null ]) : void
Parameters
- $regex : string
- $options : array<string, mixed>|callable = []
- $handler : callable|null = null
- $methods : array<int, string> = []
- $raw : bool = false
- $middleware : array<int, MiddlewareInterface|string> = []
- $backend : array<string, mixed>|string|null = null
-
Per-route CGI backend (bare mode /
App::cgiBackendAlias()name / inline config); delegated toApp::patternRoute().
post()
public
post(string $path, callable|array<int|string, mixed> $handler[, array<string, mixed> $options = [] ][, bool $raw = false ][, array<int, MiddlewareInterface|string> $middleware = [] ][, array<string, mixed>|string|null $backend = null ]) : void
Parameters
- $path : string
- $handler : callable|array<int|string, mixed>
- $options : array<string, mixed> = []
- $raw : bool = false
- $middleware : array<int, MiddlewareInterface|string> = []
- $backend : array<string, mixed>|string|null = null
put()
public
put(string $path, callable|array<int|string, mixed> $handler[, array<string, mixed> $options = [] ][, bool $raw = false ][, array<int, MiddlewareInterface|string> $middleware = [] ][, array<string, mixed>|string|null $backend = null ]) : void
Parameters
- $path : string
- $handler : callable|array<int|string, mixed>
- $options : array<string, mixed> = []
- $raw : bool = false
- $middleware : array<int, MiddlewareInterface|string> = []
- $backend : array<string, mixed>|string|null = null
route()
public
route(string $path[, array<string, mixed>|callable $options = [] ][, callable|array<int|string, mixed>|null $handler = null ][, array<int, string> $methods = [] ][, bool $raw = false ][, array<int, MiddlewareInterface|string> $middleware = [] ][, array<string, mixed>|string|null $backend = null ]) : void
Parameters
- $path : string
- $options : array<string, mixed>|callable = []
- $handler : callable|array<int|string, mixed>|null = null
- $methods : array<int, string> = []
- $raw : bool = false
- $middleware : array<int, MiddlewareInterface|string> = []
- $backend : array<string, mixed>|string|null = null
-
Per-route CGI backend (bare mode /
App::cgiBackendAlias()name / inline config); delegated toApp::route().
combine()
Group prefix + middleware ++ the route's own (options then named arg).
private
combine(array<string, mixed> $options, array<int, MiddlewareInterface|string> $middleware) : array<int, MiddlewareInterface|string>
Group middleware ends up outermost.
Parameters
- $options : array<string, mixed>
- $middleware : array<int, MiddlewareInterface|string>
Return values
array<int, MiddlewareInterface|string>joinPath()
Join the group prefix to a child path (or nested-group prefix), collapsing
the boundary slash so a trailing-slash prefix never produces a double slash
(#308). group('/admin/')->route('/users') → /admin/users, not the
unreachable /admin//users. An empty path yields the bare prefix; a missing
leading slash on the path is also normalised (route('users') works).
private
joinPath(string $prefix, string $path) : string
Parameters
- $prefix : string
- $path : string
Return values
stringnormalizeShorthand()
Apply the "second arg is the handler" shorthand ($g->route('/x', $fn)).
private
normalizeShorthand(array<string, mixed>|callable $options, callable|array<int|string, mixed>|null $handler) : array{0: array, 1: callable|array|null}
Options are rebuilt with string keys — an options array is always
string-keyed (methods/raw/middleware); the rebuild also discards the
int|string key ambiguity PHPStan infers from the callable-array union.
Parameters
- $options : array<string, mixed>|callable
- $handler : callable|array<int|string, mixed>|null
Return values
array{0: arrayprefixNamespace()
private
prefixNamespace(string $namespace) : string
Parameters
- $namespace : string
Return values
stringstripMiddleware()
private
stripMiddleware(array<string, mixed> $options) : array<string, mixed>
Parameters
- $options : array<string, mixed>