Session
in package
Session library.
Table of Contents
Properties
- $config : array<string|int, mixed>
- $driver : SessionDriver|null
- $flash : array<string|int, mixed>
- $instance : Session|null
- $protect : array<string|int, string>
Methods
- __construct() : mixed
- On first session instance creation, sets up the driver and creates session.
- create() : void
- Create a new session.
- deletall() : mixed
- Removes all session variables.
- delete() : void
- Delete one or more variables.
- destroy() : void
- Destroys the current session.
- expireFlash() : void
- Expires old flash data and removes it from the session.
- get() : mixed
- Get a variable. Access to sub-arrays is supported with key.subkey.
- getOnce() : mixed
- Get a variable, and delete it.
- has() : bool
- id() : string
- Get the session id.
- instance() : mixed
- Singleton instance of Session.
- keepFlash() : void
- Freshen one, multiple or all flash variables.
- list() : array<string|int, mixed>
- Return the entire session object.
- regenerate() : void
- Regenerates the global session id.
- set() : void
- Set a session variable.
- setFlash() : void
- Set a flash variable.
- writeClose() : void
- Runs the system.session_write event, then calls session_write_close.
Properties
$config
protected
static array<string|int, mixed>
$config
Configuration and driver
$driver
protected
static SessionDriver|null
$driver
driver
$flash
protected
static array<string|int, mixed>
$flash
Flash variables
$instance
protected
static Session|null
$instance
singleton
$protect
protected
static array<string|int, string>
$protect
= array('session_id', 'user_agent', 'last_activity', 'ip_address', 'total_hits', '_kf_flash_')
Protected key names (cannot be set by the user)
Methods
__construct()
On first session instance creation, sets up the driver and creates session.
public
__construct() : mixed
create()
Create a new session.
public
static create([array<string|int, mixed>|null $vars = null ]) : void
Parameters
- $vars : array<string|int, mixed>|null = null
-
Variables to set after creation
deletall()
Removes all session variables.
public
static deletall() : mixed
delete()
Delete one or more variables.
public
static delete(string ...$args) : void
Parameters
- $args : string
-
variable key(s)
destroy()
Destroys the current session.
public
static destroy() : void
expireFlash()
Expires old flash data and removes it from the session.
public
static expireFlash() : void
get()
Get a variable. Access to sub-arrays is supported with key.subkey.
public
static get([string|false $key = false ][, mixed $default = false ]) : mixed
Parameters
- $key : string|false = false
-
Variable key
- $default : mixed = false
-
Default value returned if variable does not exist
Return values
mixed —Variable data if key specified, otherwise array containing all session data.
getOnce()
Get a variable, and delete it.
public
static getOnce(string $key[, mixed $default = false ]) : mixed
Parameters
- $key : string
-
Variable key
- $default : mixed = false
-
Default value returned if variable does not exist
has()
public
static has(string $key) : bool
Parameters
- $key : string
Return values
boolid()
Get the session id.
public
static id() : string
Note, if the session is not yet started this returns an empty string.
Return values
stringinstance()
Singleton instance of Session.
public
static instance() : mixed
keepFlash()
Freshen one, multiple or all flash variables.
public
static keepFlash(string ...$keys) : void
Parameters
- $keys : string
-
variable key(s)
list()
Return the entire session object.
public
static list() : array<string|int, mixed>
Return values
array<string|int, mixed>regenerate()
Regenerates the global session id.
public
static regenerate() : void
set()
Set a session variable.
public
static set(string|array<string|int, mixed> $keys[, mixed $val = false ]) : void
Parameters
- $keys : string|array<string|int, mixed>
-
Key, or array of values
- $val : mixed = false
-
Value (if keys is not an array)
setFlash()
Set a flash variable.
public
static setFlash(string|array<string|int, mixed> $keys[, mixed $val = false ]) : void
Parameters
- $keys : string|array<string|int, mixed>
-
Key, or array of values
- $val : mixed = false
-
Value (if keys is not an array)
writeClose()
Runs the system.session_write event, then calls session_write_close.
public
static writeClose() : void