class Session

Session class.

Constants

MAX_TOKENS

Maximum number of tokens stored per session.

Properties

protected bool $destroyed Has the session been destroyed?
protected Request $request Request.
protected Response $response Response.
protected StoreInterface $store Session store.
protected bool $autoCommit Should the session data be commited automatically?
protected array $options Session options.
protected string $sessionId Session id.
protected array $sessionData Session data.
protected array $flashData Flashdata.
protected string $token Session token.

Methods

__construct(Request $request, Response $response, StoreInterface $store, array $options = [], bool $autoCommit = true)

Constructor.

__destruct()

Destructor.

start()

Starts the session.

commit()

Writes data to session store.

gc()

Calls the session store garbage collector.

string
generateId()

Generates a session id.

setCookie()

Adds a session cookie to the response.

loadData()

Loads the session data.

string
getId()

Returns the session id.

string
regenerateId(bool $keepOld = false)

Regenerate the session id and returns it.

array
getData()

Returns all the seesion data.

put(string $key, mixed $value)

Store a value in the session.

bool
has(string $key)

Returns TRUE if key exists in the session and FALSE if not.

mixed
get(string $key, mixed $default = null)

Returns a value from the session.

mixed
getAndPut(string $key, mixed $value, mixed $default = null)

Gets a value from the session and replaces it.

mixed
getAndRemove(string $key, mixed $default = null)

Gets a value from the session and removes it.

remove(string $key)

Removes a value from the session.

mixed
putFlash(string $key, mixed $value)

Store a flash value in the session.

bool
hasFlash(string $key)

Returns TRUE if key exists in the session and FALSE if not.

mixed
getFlash(string $key, mixed $default = null)

Returns a flash value from the session.

removeFlash(string $key)

Removes a value from the session.

reflash(array $keys = [])

Extends the lifetime of the flash data by one request.

string
getToken()

Returns the session token.

string
regenerateToken()

Generates a new session token and returns it.

bool
validateToken(string $token)

Validates the provided token.

string
generateOneTimeToken()

Returns random security token.

bool
validateOneTimeToken(string $token)

Validates security token.

clear()

Clears all session data.

destroy()

Destroys the session.

Details

at line 129
__construct(Request $request, Response $response, StoreInterface $store, array $options = [], bool $autoCommit = true)

Constructor.

Parameters

Request $request Request instance
Response $response Response instance
StoreInterface $store Session store instance
array $options Session options
bool $autoCommit Should the session data be commited automatically?

at line 149
__destruct()

Destructor.

at line 160
protected start()

Starts the session.

at line 192
commit()

Writes data to session store.

at line 209
protected gc()

Calls the session store garbage collector.

at line 222
protected string generateId()

Generates a session id.

Return Value

string

at line 230
protected setCookie()

Adds a session cookie to the response.

at line 243
protected loadData()

Loads the session data.

at line 253
string getId()

Returns the session id.

Return Value

string

at line 264
string regenerateId(bool $keepOld = false)

Regenerate the session id and returns it.

Parameters

bool $keepOld Keep the session data associated with the old session id?

Return Value

string

at line 289
array getData()

Returns all the seesion data.

Return Value

array

at line 300
put(string $key, mixed $value)

Store a value in the session.

Parameters

string $key Session key
mixed $value Session data

at line 311
bool has(string $key)

Returns TRUE if key exists in the session and FALSE if not.

Parameters

string $key Session key

Return Value

bool

at line 323
mixed get(string $key, mixed $default = null)

Returns a value from the session.

Parameters

string $key Session key
mixed $default Default value

Return Value

mixed

at line 336
mixed getAndPut(string $key, mixed $value, mixed $default = null)

Gets a value from the session and replaces it.

Parameters

string $key Session key
mixed $value Session data
mixed $default Default value

Return Value

mixed

at line 352
mixed getAndRemove(string $key, mixed $default = null)

Gets a value from the session and removes it.

Parameters

string $key Session key
mixed $default Default value

Return Value

mixed

at line 366
remove(string $key)

Removes a value from the session.

Parameters

string $key Session key

at line 378
mixed putFlash(string $key, mixed $value)

Store a flash value in the session.

Parameters

string $key Flash key
mixed $value Flash data

Return Value

mixed

at line 389
bool hasFlash(string $key)

Returns TRUE if key exists in the session and FALSE if not.

Parameters

string $key Session key

Return Value

bool

at line 401
mixed getFlash(string $key, mixed $default = null)

Returns a flash value from the session.

Parameters

string $key Session key
mixed $default Default value

Return Value

mixed

at line 411
removeFlash(string $key)

Removes a value from the session.

Parameters

string $key Session key

at line 421
reflash(array $keys = [])

Extends the lifetime of the flash data by one request.

Parameters

array $keys Keys to preserve

at line 435
string getToken()

Returns the session token.

Return Value

string

at line 445
string regenerateToken()

Generates a new session token and returns it.

Return Value

string

at line 456
bool validateToken(string $token)

Validates the provided token.

Parameters

string $token Token to validate

Return Value

bool

at line 466
string generateOneTimeToken()

Returns random security token.

Return Value

string

at line 490
bool validateOneTimeToken(string $token)

Validates security token.

Parameters

string $token Security token

Return Value

bool

at line 511
clear()

Clears all session data.

at line 519
destroy()

Destroys the session.