Skip to content
docsv0.9.0

FileSessionStore

A session ledger on disk — the persistent counterpart of {@see InMemorySessionStore}, so a session minted in one request is still there in the next. {@see InMemorySessionStore} is enough within a single process (a test, a long-lived worker); a real HTTP login spans separate PHP processes, and needs its sessions to outlive the request that made them. This holds the same fail-closed contract — an expired or revoked record reads as absent, never as a live actor — over a JSON file with locked writes, mirroring the framework's other file stores.

FileSessionStore::__construct()

public function __construct(string $path, ?callable $clock = null):

Parameters

Parameters of __construct()
NameTypeDescription
$pathstring
$clock(callable(): \DateTimeImmutable | null)the clock expiry is evaluated against

FileSessionStore::read()

public function read(string $sessionId): ?Milpa\Auth\SessionRecord

The live session under this id, or null when none is stored, or it is expired or revoked (fail-closed).

Parameters

Parameters of read()
NameTypeDescription
$sessionIdstring

FileSessionStore::write()

public function write(Milpa\Auth\SessionRecord $session): void

Persist a session on disk, keyed by its id, under an exclusive lock.

Parameters

Parameters of write()
NameTypeDescription
$sessionMilpa\Auth\SessionRecord

FileSessionStore::destroy()

public function destroy(string $sessionId): void

Remove the session under this id; a no-op when none is stored.

Parameters

Parameters of destroy()
NameTypeDescription
$sessionIdstring