Skip to content

Internals Router Security SessionTokenStore

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

router\security\SessionTokenStore

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/router/security/SessionTokenStore.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 router\interface\ICsrfTokenStore;
use session\SessionHandler;

SessionTokenStore

Declaration and architectural role

final class SessionTokenStore implements ICsrfTokenStore

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 public function __construct(private readonly SessionHandler $session = new SessionHandler()) Initialized from the constructor argument; default expression is evaluated when the argument is omitted.

Method index

Method Signature
__construct public function __construct(private readonly SessionHandler $session = new SessionHandler())
start private function start(): void
get public function get(string $name): ?string
put public function put(string $name, string $token): void

__construct

Source line 10

public function __construct(private readonly SessionHandler $session = new SessionHandler());

Parameters

Parameter Type, modifiers and default Purpose
$session private readonly SessionHandler $session = new SessionHandler() 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.

start

Source line 12

private function start(): void

Explicit exceptions: \RuntimeException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.

Implementation, validation guards and interaction order
private function start(): void
    {
        if (session_status() !== PHP_SESSION_ACTIVE) {
            $this->session->SessionHandler();
        }
        if (session_status() !== PHP_SESSION_ACTIVE) {
            throw new \RuntimeException('CSRF protection requires an active session.');
        }
    }

get

Source line 22

public function get(string $name): ?string

Parameters

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): is_string($token) ? $token : null.

Implementation, validation guards and interaction order
public function get(string $name): ?string
    {
        $this->start();
        $token = $_SESSION[$name] ?? null;
        return is_string($token) ? $token : null;
    }

put

Source line 29

public function put(string $name, string $token): void

Parameters

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.
$token string $token Operation input; the exact use, validation and propagation are shown in the implementation trace.

Delegates to start().

Implementation, validation guards and interaction order
public function put(string $name, string $token): void
    {
        $this->start();
        $_SESSION[$name] = $token;
    }

Related types

Clone this wiki locally