Repository navigation
Internals Router Manager RouterManager
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/router/manager/RouterManager.php · Snapshot 8411f4287706.
Routing separates definition, HTTP request snapshot, matching, method policy, execution and error responses. Collaborators can be replaced through constructor injection.
use event\EventDispatcher;
use redirect\Redirect;
use response\Response;
use router\http\GlobalsRequestProvider;
use router\interface\IRequest;
use router\interface\IRequestProvider;
use router\interface\IRoute;
use router\interface\IRouterManager;
use router\interface\IRouteResolver;
use router\interface\IRouteResponseFactory;
use router\matching\RouteResolver;
use router\response\RouteResponseFactory;
use view\View;final class RouterManager implements IRouterManagerSource description (behavioral corrections are recorded in Known discrepancies):
Registers route contracts and coordinates replaceable resolution and responses.
Declarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.
| Member | Declaration | Purpose or source contract |
|---|---|---|
| $routesName | private array $routesName = []; |
@var array<string, IRoute> |
| $eventDispatcher | public EventDispatcher $eventDispatcher; |
Used by __construct(), addEventDispatcher(), addRouter(). |
| Constructor-promoted | private readonly IRequestProvider $requests = new GlobalsRequestProvider() |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Constructor-promoted | private readonly IRouteResolver $resolver = new RouteResolver() |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Constructor-promoted | private readonly IRouteResponseFactory $responses = new RouteResponseFactory() |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Method | Signature |
|---|---|
| __construct | public function __construct( private readonly IRequestProvider $requests = new GlobalsRequestProvider(), private readonly IRouteResolver $resolver = new RouteResolver(), private readonly IRouteResponseFactory $responses = new RouteResponseFactory(), ?EventDispatcher $eventDispatcher = null, ) |
| addEventDispatcher | public function addEventDispatcher(EventDispatcher $eventDispatcher): self |
| addRouter | public function addRouter(IRoute $router): void |
| loadRouters | public function loadRouters(array $routers): void |
| getRoutes | public function getRoutes(): array |
| getRouters | public function getRouters(): array |
| getRouteByName | public function getRouteByName(string $name): ?IRoute |
| getRouteByPath | public function getRouteByPath(string $path, string $method = 'GET'): ?IRoute |
| startRouter | public function startRouter(?IRequest $request = null): View|Redirect|Response |
public function __construct(
private readonly IRequestProvider $requests = new GlobalsRequestProvider(),
private readonly IRouteResolver $resolver = new RouteResolver(),
private readonly IRouteResponseFactory $responses = new RouteResponseFactory(),
?EventDispatcher $eventDispatcher = null,
)| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$requests |
private readonly IRequestProvider $requests = new GlobalsRequestProvider() |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$resolver |
private readonly IRouteResolver $resolver = new RouteResolver() |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$responses |
private readonly IRouteResponseFactory $responses = new RouteResponseFactory() |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$eventDispatcher |
?EventDispatcher $eventDispatcher = null |
Dispatcher used for synchronous listener registration/dispatch and context propagation. |
State writes: $this->eventDispatcher.
Implementation, validation guards and interaction order
public function __construct(
private readonly IRequestProvider $requests = new GlobalsRequestProvider(),
private readonly IRouteResolver $resolver = new RouteResolver(),
private readonly IRouteResponseFactory $responses = new RouteResponseFactory(),
?EventDispatcher $eventDispatcher = null,
) {
$this->eventDispatcher = $eventDispatcher ?? new EventDispatcher();
}public function addEventDispatcher(EventDispatcher $eventDispatcher): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$eventDispatcher |
EventDispatcher $eventDispatcher |
Dispatcher used for synchronous listener registration/dispatch and context propagation. |
State writes: $this->eventDispatcher.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function addEventDispatcher(EventDispatcher $eventDispatcher): self
{
$this->eventDispatcher = $eventDispatcher;
foreach ($this->routesName as $route) {
$route->addEventDispatcher($eventDispatcher);
}
return $this;
}public function addRouter(IRoute $router): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$router |
IRoute $router |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->routesName[$router->getName()].
Implementation, validation guards and interaction order
public function addRouter(IRoute $router): void
{
$name = $router->getName();
if ($name === null || trim($name) === '') {
$index = count($this->routesName);
while (isset($this->routesName[(string) $index])) {
$index++;
}
$router->setName((string) $index);
}
$router->addEventDispatcher($this->eventDispatcher);
$this->routesName[$router->getName()] = $router;
}public function loadRouters(array $routers): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$routers |
array $routers |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Delegates to addRouter().
Implementation, validation guards and interaction order
public function loadRouters(array $routers): void
{
foreach ($routers as $router) {
$this->addRouter($router);
}
}public function getRoutes(): arrayReturn expressions (including local callbacks): $this->routesName.
Implementation, validation guards and interaction order
public function getRoutes(): array { return $this->routesName; }public function getRouters(): arrayReturn expressions (including local callbacks): $this->getRoutes().
Implementation, validation guards and interaction order
public function getRouters(): array { return $this->getRoutes(); }public function getRouteByName(string $name): ?IRoute| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$name |
string $name |
Named key/label selected by this API; its exact scope is shown by the implementation trace. |
Return expressions (including local callbacks): $this->routesName[$name] ?? null.
Implementation, validation guards and interaction order
public function getRouteByName(string $name): ?IRoute
{
return $this->routesName[$name] ?? null;
}public function getRouteByPath(string $path, string $method = 'GET'): ?IRoute| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$path |
string $path |
Filesystem or route path as defined by the owning component; no universal path normalization is implied. |
$method |
string $method = 'GET' |
HTTP method token; validation/normalization follows the method policy. |
Return expressions (including local callbacks): $route; null.
Implementation, validation guards and interaction order
public function getRouteByPath(string $path, string $method = 'GET'): ?IRoute
{
foreach ($this->routesName as $route) {
if ($route->getPath() === $path && $route->getMethod() === strtoupper($method)) {
return $route;
}
}
return null;
}public function startRouter(?IRequest $request = null): View|Redirect|Response| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$request |
?IRequest $request = null |
Request snapshot consumed by matching, method and security checks. |
Return expressions (including local callbacks): $match->route->route($match->params, $request); $match->allowed !== [] ? $this->responses->methodNotAllowed($match->allowed) : $this->responses->notFound().
Implementation, validation guards and interaction order
public function startRouter(?IRequest $request = null): View|Redirect|Response
{
$request ??= $this->requests->current();
$match = $this->resolver->resolve($this->routesName, $request);
if ($match->route !== null) {
return $match->route->route($match->params, $request);
}
return $match->allowed !== []
? $this->responses->methodNotAllowed($match->allowed)
: $this->responses->notFound();
}AWT Framework Wiki · Home · Installation Guide · Developer Guide · Framework Internals
Philosophy · Architecture · Known discrepancies · Verification
Installation Guide
Developer Guide
- Learning sequence
- First package
- Package structure
- Lifecycle
- Runtimes
- Events and objects
- Routing and controllers
- Views and resources
- Database and models
- Storage and caching
- Configuration and CLI
- Responses and errors
- Extension points
Framework Internals
- Architecture
- Bootstrap
- Packages
- Runtime
- Events and context
- Objects
- HTTP routing and controllers
- Rendering
- Blade integration
- Database
- Models
- Storage and caching
- Settings
- CLI
- Identity and sessions
- Responses
- Errors
- Complete source inventory
Documentation notes