Ses
Low-level PHP session handling.
Use ->session in application code.
The session is read once and its lock released at once (read_and_close), so a slow request never holds every other request of the same visitor. Each write reopens it, takes the lock just long enough to change the file and closes it again, reading what concurrent requests wrote in the meantime.
Lifecycle 8
- start Reads the session if this request hasn't yet. $options are session_start()'s, e.g. ['gc_maxlifetime' => 3600].
- isStarted Whether this request has read the session - it may hold a flash message or the visitor's own state.
- isActive Whether the session is open for writing at this moment, holding its lock.
- hasCookie Whether the request carries a session cookie, checkable without starting a session.
- close Writes and closes the session if it is open, and forgets it was read, so the next start() reads it again.
- id The session id.
- regenerate Gives the session a new id, keeping its values.
- destroy Ends the session and clears its values.
Flash 3
- setFlash Stores a value for the next request only.
- getFlash A flashed value, or null.
- deleteFlash Removes a flashed value.
Lifecycle
Ses::start(array $options = []): void
Reads the session if this request hasn't yet. $options are session_start()'s, e.g. ['gc_maxlifetime' => 3600].
Parameters (1)
| $options | array = [] |
phlat/src/Toolkit/Ses.php:26
Ses::isStarted(): bool
Whether this request has read the session - it may hold a flash message or the visitor's own state.
Returns bool
phlat/src/Toolkit/Ses.php:36
Ses::isActive(): bool
Whether the session is open for writing at this moment, holding its lock.
Returns bool
phlat/src/Toolkit/Ses.php:42
Ses::hasCookie(): bool
Whether the request carries a session cookie, checkable without starting a session.
Returns bool
phlat/src/Toolkit/Ses.php:48
Ses::close(): void
Writes and closes the session if it is open, and forgets it was read, so the next start() reads it again.
phlat/src/Toolkit/Ses.php:54
Ses::regenerate(): bool
Gives the session a new id, keeping its values.
Returns bool
phlat/src/Toolkit/Ses.php:68
Data
Ses::get(string $key): mixed
The value under $key, or null.
Parameters (1)
| $key | string |
Returns mixed
phlat/src/Toolkit/Ses.php:97
Ses::set(string $key, mixed $value): void
Stores a value under $key.
Parameters (2)
| $key | string | |
| $value | mixed |
phlat/src/Toolkit/Ses.php:103
Ses::ensure(string $key, mixed $value): mixed
The value under $key, storing $value first when there is none.
Parameters (2)
| $key | string | |
| $value | mixed |
Returns mixed
phlat/src/Toolkit/Ses.php:111
Ses::has(string $key): bool
Whether a value is stored under $key.
Parameters (1)
| $key | string |
Returns bool
phlat/src/Toolkit/Ses.php:119
Ses::delete(string $key): void
Removes the value under $key.
Parameters (1)
| $key | string |
phlat/src/Toolkit/Ses.php:125
Flash
Ses::setFlash(string $key, mixed $value): void
Stores a value for the next request only.
Parameters (2)
| $key | string | |
| $value | mixed |
phlat/src/Toolkit/Ses.php:143
Ses::getFlash(string $key): mixed
A flashed value, or null.
Parameters (1)
| $key | string |
Returns mixed
phlat/src/Toolkit/Ses.php:151
Ses::deleteFlash(string $key): void
Removes a flashed value.
Parameters (1)
| $key | string |
phlat/src/Toolkit/Ses.php:157