PHP Class lithium\storage\Session
The Session layer of Lithium inherits from the common
Adaptable class, which provides
the generic configuration setting & retrieval logic, as well as the logic required to
locate & instantiate the proper adapter class.
In most cases, you will configure various named session configurations in your bootstrap
process, which will then be available to you in all other parts of your application.
Each adapter provides a consistent interface for the basic cache operations of
write,
read
and
delete, which can be used interchangably between all adapters.
For more information on
Session methods and specific adapters, please see their relevant
documentation.
Mostra file
Open project: unionofrad/lithium
Class Usage Examples
Protected Properties
Property |
Type |
Description |
|
$_adapters |
string |
A dot-separated path for use by Libraries::locate(). Used to look up the correct type of
adapters for this class. |
|
$_configurations |
array |
Stores configurations arrays for session adapters, keyed by configuration name. |
|
$_strategies |
string |
Libraries::locate() compatible path to strategies for this class. |
|
Public Methods
Method |
Description |
|
adapter ( string $name = null ) : object |
Returns the adapter object instance of the named configuration. |
|
check ( string $key, array $options = [] ) : boolean |
Checks if a session key is set in any adapter, or if a particular adapter configuration is
specified (via 'name' in $options), only that configuration is checked. |
|
clear ( array $options = [] ) |
Clears all keys from a single adapter (if a 'name' options is specified) or all
session adapters. |
|
delete ( string $key, array $options = [] ) : boolean |
Deletes a named key from a single adapter (if a 'name' option is specified) or all
session adapters. |
|
isStarted ( string $name = null ) : boolean |
Indicates whether the the current request includes information on a previously started
session. |
|
key ( mixed $name = null, $sessionId = null ) : string |
Returns (and Sets) the key used to identify the session. |
|
read ( string $key = null, array $options = [] ) : mixed |
Reads a value from a persistent session store. |
|
write ( string $key, mixed $value = null, array $options = [] ) : boolean |
Writes a persistent value to one or more session stores. |
|
Method Details
adapter()
public static method
Returns the adapter object instance of the named configuration.
public static adapter ( string $name = null ) : object |
$name |
string |
Named configuration. If not set, the last configured
adapter object instance will be returned. |
return |
object |
Adapter instance. |
check()
public static method
Checks if a session key is set in any adapter, or if a particular adapter configuration is
specified (via 'name' in $options), only that configuration is checked.
clear()
public static method
Clears all keys from a single adapter (if a 'name' options is specified) or all
session adapters.
public static clear ( array $options = [] ) |
$options |
array |
Optional parameters that this method accepts:
- `'name'` _string_: To force the write to a specific adapter, specify the name
of the configuration (i.e. `'default'`) here.
- `'strategies'` _boolean_: Indicates whether or not a configuration's applied
strategy classes should be enabled for this operation. Defaults to `true`. |
delete()
public static method
Deletes a named key from a single adapter (if a 'name' option is specified) or all
session adapters.
public static delete ( string $key, array $options = [] ) : boolean |
$key |
string |
The name of the session key to delete. |
$options |
array |
Optional parameters that this method accepts:
- `'name'` _string_: To force the delete to a specific adapter, specify the name
of the configuration (i.e. `'default'`) here.
- `'strategies'` _boolean_: Indicates whether or not a configuration's applied
strategy classes should be enabled for this operation. Defaults to `true`. |
return |
boolean |
Returns `true` on successful delete, or `false` on failure. |
isStarted()
public static method
Indicates whether the the current request includes information on a previously started
session.
public static isStarted ( string $name = null ) : boolean |
$name |
string |
Optional named session configuration. |
return |
boolean |
Returns `true` if a the request includes a key from a previously created
session. |
key()
public static method
Returns (and Sets) the key used to identify the session.
public static key ( mixed $name = null, $sessionId = null ) : string |
$name |
mixed |
Optional named session configuration. |
return |
string |
Returns the value of the session identifier key, or `null` if no named
configuration exists, no session id has been set or no session has been started. |
read()
public static method
Reads a value from a persistent session store.
public static read ( string $key = null, array $options = [] ) : mixed |
$key |
string |
Key to be read. |
$options |
array |
Optional parameters that this method accepts:
- `'name'` _string_: To force the read from a specific adapter, specify the name
of the configuration (i.e. `'default'`) here.
- `'strategies'` _boolean_: Indicates whether or not a configuration's applied
strategy classes should be enabled for this operation. Defaults to `true`. |
return |
mixed |
Read result on successful session read, `null` otherwise. |
write()
public static method
Writes a persistent value to one or more session stores.
public static write ( string $key, mixed $value = null, array $options = [] ) : boolean |
$key |
string |
Key to be written. |
$value |
mixed |
Data to be stored. |
$options |
array |
Optional parameters that this method accepts:
- `'name'` _string_: To force the write to a specific adapter, specify the name
of the configuration (i.e. `'default'`) here.
- `'strategies'` _boolean_: Indicates whether or not a configuration's applied
strategy classes should be enabled for this operation. Defaults to `true`. |
return |
boolean |
Returns `true` on successful write, `false` otherwise. |
Property Details
$_adapters protected_oe static_oe property
A dot-separated path for use by Libraries::locate(). Used to look up the correct type of
adapters for this class.
protected static string $_adapters |
return |
string |
|
$_configurations protected_oe static_oe property
Stores configurations arrays for session adapters, keyed by configuration name.
protected static array $_configurations |
return |
array |
|
$_strategies protected_oe static_oe property
Libraries::locate() compatible path to strategies for this class.
protected static string $_strategies |
return |
string |
|