DatabaseSessionStorage
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
Defines the table, sliding retention, browser identity, and bounded request GC policy.
Loads a live row or creates a fresh identity, then refreshes row and cookie expiry.
Reports whether this request has established its database-backed identity.
Checks the payload loaded for this request.
Returns a loaded value or the supplied fallback.
Persists a value and renews the row expiry.
Removes one value and renews the row expiry.
Persists an empty payload while retaining the active identity and cookie.
Deletes the active row and expires its cookie so later access starts a new identity.
Copies the payload to a fresh identity and optionally invalidates the old row.
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.
start
void
start()
Loads a live row or creates a fresh identity, then refreshes row and cookie expiry.
started
bool
started()
Reports whether this request has established its database-backed identity.
has
bool
has(string $key)
Checks the payload loaded for this request.
get
mixed
get(string $key, mixed $default = null)
Returns a loaded value or the supplied fallback.
set
void
set(string $key, mixed $value)
Persists a value and renews the row expiry.
remove
void
remove(string $key)
Removes one value and renews the row expiry.
clear
void
clear()
Persists an empty payload while retaining the active identity and cookie.
destroy
void
destroy()
Deletes the active row and expires its cookie so later access starts a new identity.
regenerate
void
regenerate(bool $deleteOldSession = true)
Copies the payload to a fresh identity and optionally invalidates the old row.