Class: Session
Full name: Azera\Http\Session
Wrapper around a PHP session array that provides typed accessors and a clean API for reading, writing, and clearing session data.
Public methods
__construct() ·
public function __construct(array &$store): mixed
Create a new Session backed by the given store reference.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$store |
array | - | Reference to the underlying session array (typically $_SESSION). |
Return value
- Type:
mixed
get() ·
public function get(string $key, mixed $default = null): mixed
Retrieve a value from the session.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key |
string | - | Session key. |
$default |
mixed | null |
Value to return when the key is not set. |
Return value
- Type:
mixed
set() ·
public function set(string $key, mixed $value): void
Store a value in the session.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key |
string | - | Session key. |
$value |
mixed | - | Value to store. |
Return value
- Type:
void
remove() ·
public function remove(string $key): void
Remove a key from the session.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key |
string | - | Session key to unset. |
Return value
- Type:
void
has() ·
public function has(string $key): bool
Check whether a key exists in the session.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key |
string | - | Session key. |
Return value
- Type:
bool - Description: True if the key is set and not null.
clear() ·
public function clear(): void
Remove all data from the session.
Return value
- Type:
void
isActive() ·
public function isActive(): bool
Whether a PHP session is active.
The lifecycle helpers use this status to determine their behavior in
controllers, CLI tasks, and tests, with or without SessionMiddleware.
Return value
- Type:
bool
id() ·
public function id(): string
Return the current session ID, or '' when no session is active.
This method reads the ID; use regenerateId() to change it. The ID
can be used in audit logs or to correlate a request with a stored session
without accessing the session superglobal.
Return value
- Type:
string
regenerateId() ·
public function regenerateId(bool $deleteOldSession = true): bool
Issue a new session ID while keeping the session data.
Regenerate the ID after login or a privilege change, such as a role grant or the start of impersonation, so the authenticated session uses a new ID.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$deleteOldSession |
bool | true |
Whether to delete the previous session's storage. |
Return value
- Type:
bool - Description: True when a new ID was issued; false when no session is active
or the SAPI cannot regenerate it (for example, after output has started).
destroy() ·
public function destroy(): void
Destroy the active session and clear this store.
PHP's session_destroy() removes server-side data while leaving
$_SESSION populated for the rest of the request. Clearing the store
keeps subsequent reads in the request consistent with the destroyed
session.
When a session is active, it is destroyed before the store is cleared.
The subsequent session_write_close() in SessionMiddleware
returns false when the session is inactive.
Return value
- Type:
void