Aplus Framework Docs

Session
in package

Class Session.

Table of Contents

$debugCollector  : SessionCollector
$options  : array<string|int, mixed>
$saveHandler  : SaveHandler
__construct()  : mixed
Session constructor.
__destruct()  : mixed
__get()  : mixed
__isset()  : bool
__set()  : void
__unset()  : void
abort()  : bool
Discard session data changes and end session.
activate()  : bool
Make sure the session is active.
destroy()  : bool
Destroys all data registered to a session.
destroyCookie()  : bool
Sets a Cookie with the session name to be destroyed in the user-agent.
gc()  : false|int
Perform session data garbage collection.
get()  : mixed
Gets one session item.
getAll()  : array<string|int, mixed>
Get all session items.
getFlash()  : mixed
Get a Flash Data item.
getMulti()  : array<string, mixed>
Get multiple session items.
getTemp()  : mixed
Get a Temp Data item.
has()  : bool
Tells if the session has an item.
id()  : false|string
Get/Set the session id.
isActive()  : bool
Tells if sessions are enabled, and one exists.
regenerateId()  : bool
Update the current session id with a newly generated one.
remove()  : static
Remove (unset) a session item.
removeAll()  : static
Remove (unset) all session items.
removeFlash()  : static
Remove a Flash Data item.
removeMulti()  : static
Remove (unset) multiple session items.
removeTemp()  : static
Remove (unset) a Temp Data item.
reset()  : bool
Re-initialize session array with original values.
set()  : static
Set a session item.
setDebugCollector()  : static
setFlash()  : static
Set a Flash Data item, available only in the next time the session is started.
setMulti()  : static
Set multiple session items.
setTemp()  : static
Set a Temp Data item.
start()  : bool
stop()  : bool
Write session data and end session.
autoRegenerate()  : void
Auto regenerate the session id.
clearFlash()  : void
Clears the Flash Data.
clearTemp()  : void
Clears the Temp Data.
getOptions()  : array<string, mixed>
setOptions()  : void

Properties

$options

protected array<string|int, mixed> $options = []

Methods

__construct()

Session constructor.

public __construct([array<string, int|string> $options = [] ][, SaveHandler|null $handler = null ]) : mixed
Parameters
$options : array<string, int|string> = []
$handler : SaveHandler|null = null
Return values
mixed

__destruct()

public __destruct() : mixed
Return values
mixed

__get()

public __get(string $key) : mixed
Parameters
$key : string
Return values
mixed

__isset()

public __isset(string $key) : bool
Parameters
$key : string
Return values
bool

__set()

public __set(string $key, mixed $value) : void
Parameters
$key : string
$value : mixed
Return values
void

__unset()

public __unset(string $key) : void
Parameters
$key : string
Return values
void

abort()

Discard session data changes and end session.

public abort() : bool
Return values
bool

returns true on success or false on failure

activate()

Make sure the session is active.

public activate() : bool

If it is not active, it will start it.

Tags
throws
RuntimeException

if session could not be started

Return values
bool

destroy()

Destroys all data registered to a session.

public destroy() : bool
Return values
bool

true on success or false on failure

destroyCookie()

Sets a Cookie with the session name to be destroyed in the user-agent.

public destroyCookie() : bool
Tags
throws
RuntimeException

If it could not get the session name

Return values
bool

True if the Set-Cookie header was set to invalidate the session cookie, false if output exists

gc()

Perform session data garbage collection.

public gc() : false|int

If return false, use error_get_last() to get error details.

Return values
false|int

Returns the number of deleted session data for success, false for failure

get()

Gets one session item.

public get(string $key) : mixed
Parameters
$key : string

The item key name

Return values
mixed

The item value or null if no set

getAll()

Get all session items.

public getAll() : array<string|int, mixed>
Return values
array<string|int, mixed>

The value of the $_SESSION global

getFlash()

Get a Flash Data item.

public getFlash(string $key) : mixed
Parameters
$key : string

The Flash item key name

Return values
mixed

The item value or null if not exists

getMulti()

Get multiple session items.

public getMulti(array<string|int, string> $keys) : array<string, mixed>
Parameters
$keys : array<string|int, string>

An array of key item names

Return values
array<string, mixed>

An associative array with items keys and values. Item not set will return as null.

getTemp()

Get a Temp Data item.

public getTemp(string $key) : mixed
Parameters
$key : string

The item key name

Return values
mixed

The item value or null if it is expired or not set

has()

Tells if the session has an item.

public has(string $key) : bool
Parameters
$key : string

The item key name

Return values
bool

True if it has, otherwise false

id()

Get/Set the session id.

public id([string|null $newId = null ]) : false|string
Parameters
$newId : string|null = null

[optional] The new session id

Tags
throws
LogicException

when trying to set a new id and the session is active

Return values
false|string

The old session id or false on failure. Note: If a $newId is set, it is accepted but not validated. When session_start is called, the id is only used if it is valid

isActive()

Tells if sessions are enabled, and one exists.

public isActive() : bool
Return values
bool

regenerateId()

Update the current session id with a newly generated one.

public regenerateId([bool $deleteOldSession = false ]) : bool
Parameters
$deleteOldSession : bool = false

Whether to delete the old associated session item or not

Return values
bool

remove()

Remove (unset) a session item.

public remove(string $key) : static
Parameters
$key : string

The item key name

Tags
rerun

static

Return values
static

removeAll()

Remove (unset) all session items.

public removeAll() : static
Tags
rerun

static

Return values
static

removeFlash()

Remove a Flash Data item.

public removeFlash(string $key) : static
Parameters
$key : string

The item key name

Tags
rerun

static

Return values
static

removeMulti()

Remove (unset) multiple session items.

public removeMulti(array<string|int, string> $keys) : static
Parameters
$keys : array<string|int, string>

A list of items keys names

Tags
rerun

static

Return values
static

removeTemp()

Remove (unset) a Temp Data item.

public removeTemp(string $key) : static
Parameters
$key : string

The item key name

Tags
rerun

static

Return values
static

reset()

Re-initialize session array with original values.

public reset() : bool
Return values
bool

true if the session was successfully reinitialized or false on failure

set()

Set a session item.

public set(string $key, mixed $value) : static
Parameters
$key : string

The item key name

$value : mixed

The item value

Tags
rerun

static

Return values
static

setFlash()

Set a Flash Data item, available only in the next time the session is started.

public setFlash(string $key, mixed $value) : static
Parameters
$key : string

The Flash Data item key name

$value : mixed

The item value

Tags
rerun

static

Return values
static

setMulti()

Set multiple session items.

public setMulti(array<string, mixed> $items) : static
Parameters
$items : array<string, mixed>

An associative array of items keys and values

Tags
rerun

static

Return values
static

setTemp()

Set a Temp Data item.

public setTemp(string $key, mixed $value[, int $ttl = 60 ]) : static
Parameters
$key : string

The item key name

$value : mixed

The item value

$ttl : int = 60

The Time-To-Live of the item, in seconds

Tags
rerun

static

Return values
static

start()

public start([array<string, int|string> $customOptions = [] ]) : bool
Parameters
$customOptions : array<string, int|string> = []
Tags
throws
LogicException

if session was already active

throws
RuntimeException

if session could not be started

Return values
bool

stop()

Write session data and end session.

public stop() : bool
Return values
bool

returns true on success or false on failure

clearFlash()

Clears the Flash Data.

protected clearFlash() : void
Return values
void

clearTemp()

Clears the Temp Data.

protected clearTemp(int $time) : void
Parameters
$time : int

The max time to temp data survive

Return values
void

getOptions()

protected getOptions([array<string, mixed> $custom = [] ]) : array<string, mixed>
Parameters
$custom : array<string, mixed> = []
Return values
array<string, mixed>

Search results