final class DatabaseSessionStorage implements SessionStorageInterface (View source)

Persists sliding sessions in a consumer-owned table with bounded opportunistic cleanup.

Concurrent payload mutations use last-writer-wins semantics.

Constants

private DEFAULT_GC_BATCH_SIZE

Methods

__construct(ConnectionInterface $connection, string $table = 'sessions', int $lifetimeSeconds = 7200, string $cookieName = 'LEMONADE_SESSION', int $gcBatchSize = self::DEFAULT_GC_BATCH_SIZE, SessionCookie|null $cookie = null, SessionGarbageCollectionPolicy|null $garbageCollectionPolicy = null)

Defines the table, sliding retention, browser identity, and bounded request GC policy.

void
start()

Loads a live row or creates a fresh identity, then refreshes row and cookie expiry.

void
bool

Reports whether this request has established its database-backed identity.

bool
bool
has(string $key)

Checks the payload loaded for this request.

bool
mixed
get(string $key, mixed $default = null)

Returns a loaded value or the supplied fallback.

mixed
void
set(string $key, mixed $value)

Persists a value and renews the row expiry.

void
void
remove(string $key)

Removes one value and renews the row expiry.

void
void
clear()

Persists an empty payload while retaining the active identity and cookie.

void
void

Deletes the active row and expires its cookie so later access starts a new identity.

void
void
regenerate(bool $deleteOldSession = true)

Copies the payload to a fresh identity and optionally invalidates the old row.

void

Details

__construct

__construct(ConnectionInterface $connection, string $table = 'sessions', int $lifetimeSeconds = 7200, string $cookieName = 'LEMONADE_SESSION', int $gcBatchSize = self::DEFAULT_GC_BATCH_SIZE, SessionCookie|null $cookie = null, SessionGarbageCollectionPolicy|null $garbageCollectionPolicy = null)

Defines the table, sliding retention, browser identity, and bounded request GC policy.

Parameters

ConnectionInterface $connection
string $table
int $lifetimeSeconds
string $cookieName
int $gcBatchSize
SessionCookie|null $cookie
SessionGarbageCollectionPolicy|null $garbageCollectionPolicy

start

void start()

Loads a live row or creates a fresh identity, then refreshes row and cookie expiry.

Return Value

void

started

bool started()

Reports whether this request has established its database-backed identity.

Return Value

bool

has

bool has(string $key)

Checks the payload loaded for this request.

Parameters

string $key

Return Value

bool

get

mixed get(string $key, mixed $default = null)

Returns a loaded value or the supplied fallback.

Parameters

string $key
mixed $default

Return Value

mixed

set

void set(string $key, mixed $value)

Persists a value and renews the row expiry.

Parameters

string $key
mixed $value

Return Value

void

remove

void remove(string $key)

Removes one value and renews the row expiry.

Parameters

string $key

Return Value

void

clear

void clear()

Persists an empty payload while retaining the active identity and cookie.

Return Value

void

destroy

void destroy()

Deletes the active row and expires its cookie so later access starts a new identity.

Return Value

void

regenerate

void regenerate(bool $deleteOldSession = true)

Copies the payload to a fresh identity and optionally invalidates the old row.

Parameters

bool $deleteOldSession

Return Value

void