Loader
Loader
Base contract for router definition loaders.
class LoaderLoader implementations are responsible for preparing route definitions from a specific source (for example files, attributes, or other providers) and may optionally perform request-time matching before the router falls back to in-memory route evaluation.
Lifecycle:
- Constructed by Hazaar\Application\Router with router configuration.
- Hazaar\Application\Router\Loader::initialise is called during router bootstrap.
- Hazaar\Application\Router\Loader::evaluateRequest may return a pre-resolved route for an incoming request, or
nullto defer to other router matching strategies.
Properties
config
protected Options $configType: Hazaar\Application\Router\Options
router
Owning router instance that created this loader.
protected Router $routerType: Hazaar\Application\Router
Methods
__construct
Loader constructor.
public __construct(Router $router, array|Options $config = 'new Options()'): voidParameters
| Parameter | Type | Description |
|---|---|---|
$router | Hazaar\Application\Router | |
$config | array | Hazaar\Application\Router\Options |
initialise
Initialises the basic router.
public initialise(): boolReturns: bool
evaluateRequest
Evaluates the request and sets the controller, action, and arguments based on the request path.
public evaluateRequest(Request $request): ?RouteReturns: Hazaar\Application\Route
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | Hazaar\Application\Request | the request object |
getRoutes
Returns every route this loader can statically resolve, independent of any live request.
public getRoutes(): arrayReturns: array
The default implementation simply returns whatever has already been registered directly on the router (via Router::add()/addRoute()) — correct for loaders such as file that eagerly register every route during Hazaar\Application\Router\Loader::initialise. Loaders with no such eager-registration behaviour (for example attribute, which normally only registers the one controller resolved for the current request, or basic/advanced, which never register anything at all) override this method.
scanControllers
Recursively scans every registered Controllers search path for controller classes.
protected scanControllers(): arrayReturns: array
Shared by loaders that need to statically discover every controller instead of resolving a single one from a request path (used by Hazaar\Application\Router\Loader::getRoutes overrides). Scans all paths registered for Hazaar\Application\Enum\FilePath::CONTROLLER (not just the first), since an app can register more than one via Hazaar\Loader::addSearchPath.
synthesizeRoutesForController
Synthesizes one Route per public, class-declared (non-inherited) method on a controller.
protected synthesizeRoutesForController(string $controllerClass, string $pathPrefix): arrayReturns: array
Used by router types with no static per-route declaration surface at all (basic/advanced — see their getRoutes() overrides) as a best-effort way to enumerate routes that are nonetheless perfectly real and dispatchable by naming convention. Placeholder parameter names come straight from reflection; HTTP methods are left unrestricted ([], matches any), since that's how these two router types actually dispatch.
Parameters
| Parameter | Type | Description |
|---|---|---|
$controllerClass | string | fully-qualified controller class name |
$pathPrefix | string | URL path prefix for this controller (e.g. /user), no trailing slash |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000