Session implements SessionInterface
Saving writes only the keys changed since the last save, onto what the store holds by then: concurrent requests of one session keep each other's changes as long as they change different keys.
The store reads and writes in separate steps, so two saves that overlap can still lose one of them.
Tags
Table of Contents
Interfaces
Properties
- $changes : array<string, true>|null
- Keys changed since the last save, or null once clear() or hydrate() replaced all of them.
- $data : array<string, mixed>
- Official keys are: - initialized: bool - client_info: array|null - client_capabilities: array|null - protocol_version: string|null - log_level: string|null
- $id : Uuid
- $nothingRead : bool
- Whether the first read of this session returned nothing.
- $store : SessionStoreInterface
- $stored : bool
- Whether the store held this session when it was read or last saved.
Methods
- __construct() : mixed
- all() : array<string, mixed>
- Get all attributes of the session.
- clear() : void
- Remove all attributes from the session, including who opened it: once saved, the session serves no one.
- forget() : void
- Remove an attribute from the session.
- get() : mixed
- Get a specific attribute from the session.
- getId() : Uuid
- Get the session ID.
- has() : bool
- Check if an attribute exists in the session.
- hydrate() : void
- Set all attributes of the session, typically for hydration.
- isUnreadable() : bool
- Whether the store holds this session but failed to return it, unlike a session without attributes.
- jsonSerialize() : array<string, mixed>
- pull() : mixed
- Get an attribute's value and then remove it from the session.
- save() : bool
- Save the session.
- set() : void
- Set a specific attribute in the session.
- apply() : void
- Carries the current value of a changed key over to $data, or removes it there if it was forgotten.
- load() : array<string, mixed>|null
- readData() : array<string, mixed>
- trackChange() : void
Properties
$changes
Keys changed since the last save, or null once clear() or hydrate() replaced all of them.
private
array<string, true>|null
$changes
= []
$data
Official keys are: - initialized: bool - client_info: array|null - client_capabilities: array|null - protocol_version: string|null - log_level: string|null
private
array<string, mixed>
$data
$id
private
Uuid
$id
= new UuidV4()
$nothingRead
Whether the first read of this session returned nothing.
private
bool
$nothingRead
= false
$store
private
SessionStoreInterface
$store
$stored
Whether the store held this session when it was read or last saved.
private
bool
$stored
= false
Methods
__construct()
public
__construct(SessionStoreInterface $store[, Uuid $id = new UuidV4() ]) : mixed
Parameters
- $store : SessionStoreInterface
- $id : Uuid = new UuidV4()
all()
Get all attributes of the session.
public
all() : array<string, mixed>
Return values
array<string, mixed>clear()
Remove all attributes from the session, including who opened it: once saved, the session serves no one.
public
clear() : void
forget()
Remove an attribute from the session.
public
forget(string $key) : void
Supports dot notation for nested access.
Parameters
- $key : string
get()
Get a specific attribute from the session.
public
get(string $key[, mixed $default = null ]) : mixed
Supports dot notation for nested access.
Parameters
- $key : string
- $default : mixed = null
getId()
Get the session ID.
public
getId() : Uuid
Return values
Uuidhas()
Check if an attribute exists in the session.
public
has(string $key) : bool
Supports dot notation for nested access.
Parameters
- $key : string
Return values
boolhydrate()
Set all attributes of the session, typically for hydration.
public
hydrate(array<string|int, mixed> $attributes) : void
This will overwrite existing attributes.
Parameters
- $attributes : array<string|int, mixed>
isUnreadable()
Whether the store holds this session but failed to return it, unlike a session without attributes.
public
isUnreadable() : bool
Return values
booljsonSerialize()
public
jsonSerialize() : array<string, mixed>
Return values
array<string, mixed>pull()
Get an attribute's value and then remove it from the session.
public
pull(string $key[, mixed $default = null ]) : mixed
Supports dot notation for nested access.
Parameters
- $key : string
- $default : mixed = null
save()
Save the session.
public
save() : bool
Return values
boolset()
Set a specific attribute in the session.
public
set(string $key, mixed $value[, bool $overwrite = true ]) : void
Supports dot notation for nested access.
Parameters
- $key : string
- $value : mixed
- $overwrite : bool = true
apply()
Carries the current value of a changed key over to $data, or removes it there if it was forgotten.
private
apply(array<string, mixed> &$data, string $key) : void
Parameters
- $data : array<string, mixed>
- $key : string
load()
private
load() : array<string, mixed>|null
Return values
array<string, mixed>|null —null when the store returned nothing
readData()
private
readData() : array<string, mixed>
Return values
array<string, mixed>trackChange()
private
trackChange(string $key) : void
Parameters
- $key : string