Documentation

NativeSessionStorage
in package
implements SessionStorageInterface

This provides a base class for session attribute storage.

Tags
author

Drak drak@zikula.org

Interfaces, Classes and Traits

SessionStorageInterface
StorageInterface.

Table of Contents

$bags  : array<string|int, SessionBagInterface>
$closed  : bool
$metadataBag  : MetadataBag
$saveHandler  : AbstractProxy|SessionHandlerInterface
$started  : bool
$emulateSameSite  : string|null
__construct()  : mixed
Depending on how you want the storage driver to behave you probably want to override this constructor entirely.
clear()  : mixed
Clear all session data in memory.
getBag()  : SessionBagInterface
Gets a SessionBagInterface by name.
getId()  : string
Returns the session ID.
getMetadataBag()  : MetadataBag
Gets the MetadataBag.
getName()  : string
Returns the session name.
getSaveHandler()  : AbstractProxy|SessionHandlerInterface
Gets the save handler instance.
isStarted()  : bool
Checks if the session is started.
regenerate()  : bool
Regenerates id that represents this storage.
registerBag()  : mixed
Registers a SessionBagInterface for use.
save()  : mixed
Force the session to be saved and closed.
setId()  : mixed
Sets the session ID.
setMetadataBag()  : mixed
setName()  : mixed
Sets the session name.
setOptions()  : mixed
Sets session.* ini variables.
setSaveHandler()  : mixed
Registers session save handler as a PHP session handler.
start()  : bool
Starts the session.
loadSession()  : mixed
Load the session with attributes.

Properties

Methods

__construct()

Depending on how you want the storage driver to behave you probably want to override this constructor entirely.

public __construct([array<string|int, mixed> $options = [] ][, AbstractProxy|SessionHandlerInterface|null $handler = null ][, MetadataBag|null $metaBag = null ]) : mixed

List of options for $options array with their defaults.

Parameters
$options : array<string|int, mixed> = []
$handler : AbstractProxy|SessionHandlerInterface|null = null
$metaBag : MetadataBag|null = null
Tags
see
https://php.net/session.configuration

for options but we omit 'session.' from the beginning of the keys for convenience.

("auto_start", is not supported as it tells PHP to start a session before PHP starts to execute user-land code. Setting during runtime has no effect).

cache_limiter, "" (use "0" to prevent headers from being sent entirely). cache_expire, "0" cookie_domain, "" cookie_httponly, "" cookie_lifetime, "0" cookie_path, "/" cookie_secure, "" cookie_samesite, null gc_divisor, "100" gc_maxlifetime, "1440" gc_probability, "1" lazy_write, "1" name, "PHPSESSID" referer_check, "" serialize_handler, "php" use_strict_mode, "1" use_cookies, "1" use_only_cookies, "1" use_trans_sid, "0" sid_length, "32" sid_bits_per_character, "5" trans_sid_hosts, $_SERVER['HTTP_HOST'] trans_sid_tags, "a=href,area=href,frame=src,form="

Return values
mixed

clear()

Clear all session data in memory.

public clear() : mixed
Return values
mixed

isStarted()

Checks if the session is started.

public isStarted() : bool
Return values
bool

regenerate()

Regenerates id that represents this storage.

public regenerate([bool $destroy = false ][, int|null $lifetime = null ]) : bool
Parameters
$destroy : bool = false

Destroy session when regenerating?

$lifetime : int|null = null

Sets the cookie lifetime for the session cookie. A null value will leave the system settings unchanged, 0 sets the cookie to expire with browser session. Time is in seconds, and is not a Unix timestamp.

Return values
bool

save()

Force the session to be saved and closed.

public save() : mixed
Return values
mixed

setId()

Sets the session ID.

public setId(string $id) : mixed
Parameters
$id : string
Return values
mixed

setName()

Sets the session name.

public setName(string $name) : mixed
Parameters
$name : string
Return values
mixed

setOptions()

Sets session.* ini variables.

public setOptions(array<string|int, mixed> $options) : mixed

For convenience we omit 'session.' from the beginning of the keys. Explicitly ignores other ini keys.

Parameters
$options : array<string|int, mixed>

Session ini directives [key => value]

Tags
see
https://php.net/session.configuration
Return values
mixed

setSaveHandler()

Registers session save handler as a PHP session handler.

public setSaveHandler([AbstractProxy|SessionHandlerInterface|null $saveHandler = null ]) : mixed

To use internal PHP session save handlers, override this method using ini_set with session.save_handler and session.save_path e.g.

ini_set('session.save_handler', 'files');
ini_set('session.save_path', '/tmp');

or pass in a \SessionHandler instance which configures session.save_handler in the constructor, for a template see NativeFileSessionHandler.

Parameters
$saveHandler : AbstractProxy|SessionHandlerInterface|null = null
Tags
see
https://php.net/session-set-save-handler
see
https://php.net/sessionhandlerinterface
see
https://php.net/sessionhandler
throws
InvalidArgumentException
Return values
mixed

loadSession()

Load the session with attributes.

protected loadSession([array<string|int, mixed>|null &$session = null ]) : mixed

After starting the session, PHP retrieves the session from whatever handlers are set to (either PHP's internal, or a custom save handler set with session_set_save_handler()). PHP takes the return value from the read() handler, unserializes it and populates $_SESSION with the result automatically.

Parameters
$session : array<string|int, mixed>|null = null
Return values
mixed

Search results