VELOX API Docs

Session
in package

A class that offers a simple interface to work with sessions.

Example:

// start a session
Session::start();

// check for variable availability
$someVarExists = Session::has('someVar');

// set a session variable
Session::set('someVar', $value);

// get a session variable
$someVar = Session::get('someVar');

// destroy a session
Session::destroy();

// get an instance of the Flash class
$flash = Session::flash();

// get an instance of the CSRF class
$flash = Session::csrf();
Tags
since
1.3.0

Table of Contents

__construct()  : mixed
Class constructor.
clear()  : bool
Clears the session entirely.
csrf()  : CSRF
Returns an instance of the CSRF class.
cut()  : mixed
Cuts a value from the session. The value will be returned and the key will be unset from the array.
destroy()  : bool
Destroys all of the data associated with the current session.
flash()  : Flash
Writes a flash message to the session.
get()  : mixed
Gets a value from the session.
has()  : bool
Checks if a value exists in the session.
set()  : static
Sets a value in the session.
start()  : bool
Starts the session if it is not already started.
unset()  : bool
Unsets the session superglobal This method deletes (truncates) only the variables in the session, session still exists.

Methods

__construct()

Class constructor.

public __construct([int|null $expiration = null ][, string|null $limiter = null ][, string|null $path = null ]) : mixed
Parameters
$expiration : int|null = null

Session expiration time in minutes.

$limiter : string|null = null

Session limiter.

$path : string|null = null

Session save path.

Return values
mixed

clear()

Clears the session entirely.

public static clear() : bool

This method will unset the session, destroy the session, commit (close writing) to the session, and reset the session cookie (new expiration).

Return values
bool

True if the session was cleared, false otherwise.

csrf()

Returns an instance of the CSRF class.

public static csrf([string $name = null ]) : CSRF
Parameters
$name : string = null

[optional] The name of the CSRF token. Default to {session.csrf.name} configuration value. If a token name other than the default is specified, validation of this token has to be implemented manually.

Return values
CSRF

cut()

Cuts a value from the session. The value will be returned and the key will be unset from the array.

public static cut(string $key) : mixed
Parameters
$key : string

The key to cut. Dot-notation can be used with nested arrays.

Return values
mixed

The value of the key, or null if the key does not exist.

destroy()

Destroys all of the data associated with the current session.

public static destroy() : bool

This method does not unset any of the global variables associated with the session, or unset the session cookie.

Return values
bool

True if the session was destroyed, false otherwise.

flash()

Writes a flash message to the session.

public static flash([string $text = '' ][, string $type = '' ][, bool $now = false ]) : Flash

This method can be invoked without arguments, in that case a Flash object will be returned.

Parameters
$text : string = ''

[optional] Message text.

$type : string = ''

[optional] Message type.

$now : bool = false

[optional] Whether to write and make the message available for rendering immediately or wait for the next request.

Return values
Flash

get()

Gets a value from the session.

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

The key to get. Dot-notation can be used with nested arrays.

Return values
mixed

The value of the key, or null if the key does not exist.

has()

Checks if a value exists in the session.

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

The key to check. Dot-notation can be used with nested arrays.

Return values
bool

True if the key exists, false otherwise.

set()

Sets a value in the session.

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

The key to set. Dot-notation can be used with nested arrays.

$value : mixed

The value to set.

Return values
static

The current instance.

start()

Starts the session if it is not already started.

public static start([int|null $expiration = null ][, string|null $limiter = null ][, string|null $path = null ]) : bool
Parameters
$expiration : int|null = null
$limiter : string|null = null
$path : string|null = null
Return values
bool

True if the session was started, false otherwise.

unset()

Unsets the session superglobal This method deletes (truncates) only the variables in the session, session still exists.

public static unset() : bool
Return values
bool

True if the session was unset, false otherwise.

Search results