\duncan3dc\SessionsSession

A static interface for SessionInstance.

Summary

Methods
Properties
Constants
name()
createNamespace()
get()
getAll()
set()
getSet()
delete()
clear()
getFlash()
setFlash()
destroy()
No public properties found
No constants found
getInstance()
$name
$session
N/A
No private methods found
No private properties found
N/A

Properties

$name

$name : string

Type

string — The name of the session.

Methods

name()

name(string  $name) : void

Set the name of the session to use.

Parameters

string $name

The name of the session

createNamespace()

createNamespace(string  $name) : \duncan3dc\Sessions\SessionNamespace

Create a new namespaced section of this session to avoid clashes.

Parameters

string $name

The namespace of the session

Returns

\duncan3dc\Sessions\SessionNamespace

get()

get(string  $key) : mixed

Get a value from the session data cache.

Parameters

string $key

The name of the name to retrieve

Returns

mixed

getAll()

getAll() : array

Get all the current session data.

Returns

array

set()

set(string|array  $data, mixed  $value = null) : void

Set a value within session data.

Parameters

string|array $data

Either the name of the session key to update, or an array of keys to update

mixed $value

If $data is a string then store this value in the session data

getSet()

getSet(string  $key, mixed  $default = null, boolean  $strict = false) : mixed

This is a convenience method to prevent having to do several checks/set for all persistant variables.

If the key name has been passed via POST then that value is stored in the session and returned. If the key name has been passed via GET then that value is stored in the session and returned. If there is already a value in the session data then that is returned. If all else fails then the default value is returned. All checks are truthy/falsy (so a POST value of "0" is ignored), unless the 3rd parameter is set to true.

Parameters

string $key

The name of the key to retrieve from session data

mixed $default

The value to use if the current session value is falsy

boolean $strict

Whether to do strict comparisons or not

Returns

mixed

delete()

delete(string  $keys) : void

Unset a value within session data.

Parameters

string $keys

The keys to delete from the session

clear()

clear() : void

Clear all previously set values.

getFlash()

getFlash(string  $key) : mixed

Retrieve a one-time value from the session data.

Parameters

string $key

The name of the flash value to retrieve

Returns

mixed

setFlash()

setFlash(string  $key, mixed  $value) : void

Set a one-time value within session data.

Parameters

string $key

The name of the flash value to update

mixed $value

The value to store against the key

destroy()

destroy() : void

Tear down the session and wipe all it's data.

getInstance()

getInstance() : void

Ensure the session instance has been created.