\duncan3dc\SessionsSessionInstance

A non-blocking session manager.

Summary

Methods
Properties
Constants
getSet()
delete()
clear()
getFlash()
setFlash()
__construct()
getId()
createNamespace()
get()
getAll()
set()
destroy()
No public properties found
No constants found
flashKey()
init()
$init
$name
$data
N/A
No private methods found
$id
$cookie
N/A

Properties

$init

$init : boolean

Type

boolean — Whether the session has been started or not.

$name

$name : string

Type

string — The name of the session.

$data

$data : array

Type

array — The cache of the session data.

$id

$id : string

Type

string — The session ID

Methods

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(  $keys) : static

Unset a value within session data.

Parameters

$keys

Returns

static

clear()

clear() : static

Clear all previously set values.

Returns

static

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

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

Returns

static

__construct()

__construct(string  $name, \duncan3dc\Sessions\Cookie  $cookie = null, string  $id = "") 

Create a new instance.

Parameters

string $name

The name of the session

\duncan3dc\Sessions\Cookie $cookie

The cookie settings to use

string $id

The session ID to use

getId()

getId() : string

Get the session ID.

Returns

string

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

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

Returns

static

destroy()

destroy() : static

Tear down the session and wipe all its data.

Returns

static

flashKey()

flashKey(string  $key) : string

Converts the passed session key into a flashed key.

Parameters

string $key

The key to convert

Returns

string

init()

init() : void

Ensure the session data is loaded into cache.