toolkit

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.

Ses:: Phlat\Toolkit\Ses 17 methods

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.

Data 6

  • get The value under $key, or null.
  • set Stores a value under $key.
  • ensure The value under $key, storing $value first when there is none.
  • has Whether a value is stored under $key.
  • delete Removes the value under $key.
  • all Every session value.

Flash 3

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::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

id

Ses::id(): string

The session id.

Returns string

phlat/src/Toolkit/Ses.php:62
Ses::regenerate(): bool

Gives the session a new id, keeping its values.

Returns bool

phlat/src/Toolkit/Ses.php:68
Ses::destroy(): void

Ends the session and clears its values.

phlat/src/Toolkit/Ses.php:74

Data

get

Ses::get(string $key): mixed

The value under $key, or null.

Parameters (1)
$key string

Returns mixed

phlat/src/Toolkit/Ses.php:97

set

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

has

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

all

Ses::all(): array

Every session value.

Returns array

phlat/src/Toolkit/Ses.php:135

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