Skip to content

Internals Router Execution RouteExecutor

Stefan Crkvenjakov edited this page Oct 7, 2026 · 1 revision

router\execution\RouteExecutor

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/router/execution/RouteExecutor.php · Snapshot 8411f4287706.

Routing separates definition, HTTP request snapshot, matching, method policy, execution and error responses. Collaborators can be replaced through constructor injection.

Imports and dependencies

use context\events\RespondContextEvent;
use object\ObjectFactory;
use redirect\Redirect;
use response\Response;
use router\events\RouteEnterEvent;
use router\http\HttpMethod;
use router\interface\IRequest;
use router\interface\ICsrfValidator;
use router\interface\IRouteExecutor;
use router\interface\IRoute;
use router\security\SessionCsrfValidator;
use view\View;

RouteExecutor

Declaration and architectural role

final class RouteExecutor implements IRouteExecutor

Source description (behavioral corrections are recorded in Known discrepancies):

Executes the route pipeline in security, middleware, event, action order.

Constants, enum cases, traits and properties

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
Constructor-promoted private readonly ICsrfValidator $csrfValidator = new SessionCsrfValidator() Initialized from the constructor argument; default expression is evaluated when the argument is omitted.
Constructor-promoted private readonly \router\interface\IMethodPolicy $methods = new HttpMethod() Initialized from the constructor argument; default expression is evaluated when the argument is omitted.
Constructor-promoted private readonly \router\interface\IRouteResponseFactory $responses = new \router\response\RouteResponseFactory() Initialized from the constructor argument; default expression is evaluated when the argument is omitted.

Method index

Method Signature
__construct public function __construct( private readonly ICsrfValidator $csrfValidator = new SessionCsrfValidator(), private readonly \router\interface\IMethodPolicy $methods = new HttpMethod(), private readonly \router\interface\IRouteResponseFactory $responses = new \router\response\RouteResponseFactory(), )
execute public function execute(IRoute $route, IRequest $request, array $params = []): View|Redirect|Response

__construct

Source line 21

public function __construct(
        private readonly ICsrfValidator $csrfValidator = new SessionCsrfValidator(),
        private readonly \router\interface\IMethodPolicy $methods = new HttpMethod(),
        private readonly \router\interface\IRouteResponseFactory $responses = new \router\response\RouteResponseFactory(),
    );

Parameters

Parameter Type, modifiers and default Purpose
$csrfValidator private readonly ICsrfValidator $csrfValidator = new SessionCsrfValidator() Operation input; the exact use, validation and propagation are shown in the implementation trace.
$methods private readonly \router\interface\IMethodPolicy $methods = new HttpMethod() Operation input; the exact use, validation and propagation are shown in the implementation trace.
$responses private readonly \router\interface\IRouteResponseFactory $responses = new \router\response\RouteResponseFactory() Operation input; the exact use, validation and propagation are shown in the implementation trace.

Concrete no-op/default hook: this method performs no work. Override it where the lifecycle or extension contract calls for behavior.

execute

Source line 27

public function execute(IRoute $route, IRequest $request, array $params = []): View|Redirect|Response

Parameters

Parameter Type, modifiers and default Purpose
$route IRoute $route Operation input; the exact use, validation and propagation are shown in the implementation trace.
$request IRequest $request Request snapshot consumed by matching, method and security checks.
$params array $params = [] Operation input; the exact use, validation and propagation are shown in the implementation trace.

Return expressions (including local callbacks): $this->responses->methodNotAllowed($this->methods->allowed($route->getMethod())); $this->responses->csrfRejected(); $controller->{$route->getAction()}($params).

Implementation, validation guards and interaction order
public function execute(IRoute $route, IRequest $request, array $params = []): View|Redirect|Response
    {
        if (!$this->methods->allows($route->getMethod(), $request->method())) {
            return $this->responses->methodNotAllowed($this->methods->allowed($route->getMethod()));
        }
        if ($route->requiresCsrf() && !$this->methods->isSafe($request->method())
            && !$this->csrfValidator->validate($request)) {
            return $this->responses->csrfRejected();
        }

        $route->getMiddleware()?->handle();
        $controller = $route->getController();
        if ($controller instanceof ObjectFactory) {
            $controller = $controller->create();
            $route->setController($controller);
        }
        $context = $controller->getContext();
        if ($context !== null) {
            $route->getEventDispatcher()->addListener('context.get', new RespondContextEvent($context));
        }
        $route->getEventDispatcher()->dispatch(new RouteEnterEvent($route->getPath(), $route->getAction(), $controller));
        $controller->viewName = $route->getAction();
        return $controller->{$route->getAction()}($params);
    }

Related types

Clone this wiki locally