Phalcon session
NOTE
All classes are prefixed with Phalcon
Session\Adapter\AbstractAdapter¶
Abstract Source on GitHub
Phalcon\Session\Adapter\AbstractAdapter— implementsSessionHandlerInterface,SessionUpdateTimestampHandlerInterface
Uses Phalcon\Storage\Adapter\AdapterInterface · SessionHandlerInterface · SessionUpdateTimestampHandlerInterface
Method Summary¶
public bool close() Close public bool destroy( mixed $id ) Destroy public int|false gc( int $max_lifetime ) Garbage Collector public bool open(mixed $path,mixed $name) Open public string read( mixed $id ) Read public bool updateTimestamp(mixed $id,mixed $data) Refresh the session lifetime without changing the session data public bool validateId( mixed $id ) Validate the session id (used when strict mode is enabled) public bool write(mixed $id,mixed $data) Write protected mixed getArrVal(array $collection,mixed $index,mixed $defaultValue = null) @todo Remove this when we get traits Properties¶
protected AdapterInterface $adapter Methods¶
close()¶
Close
destroy()¶
Destroy
gc()¶
Garbage Collector
open()¶
Open
read()¶
Read
updateTimestamp()¶
Refresh the session lifetime without changing the session data
validateId()¶
Validate the session id (used when strict mode is enabled)
write()¶
Write
getArrVal()¶
@todo Remove this when we get traits
Session\Adapter\Exceptions\AdapterRuntimeError¶
Class Source on GitHub
\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Adapter\Exceptions\AdapterRuntimeError
Uses Phalcon\Session\Exception
Session\Adapter\Exceptions\InvalidSavePath¶
Class Source on GitHub
\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Adapter\Exceptions\InvalidSavePath
Uses Phalcon\Session\Exception
Method Summary¶
Methods¶
__construct()¶
Session\Adapter\Exceptions\SavePathUnavailable¶
Class Source on GitHub
\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Adapter\Exceptions\SavePathUnavailable
Uses Phalcon\Session\Exception
Method Summary¶
Methods¶
__construct()¶
Session\Adapter\Libmemcached¶
Class Source on GitHub
Phalcon\Session\Adapter\Libmemcached
Phalcon\Session\Adapter\AbstractAdapterPhalcon\Session\Adapter\Libmemcached
Uses Phalcon\Storage\AdapterFactory
Method Summary¶
Methods¶
__construct()¶
Libmemcached constructor.
]
],
'defaultSerializer' => 'Php',
'lifetime' => 3600,
'serializer' => null,
'prefix' => 'sess-memc-',
'stripPrefix' => false
]
Session\Adapter\Noop¶
Class Source on GitHub
Phalcon\Session\Adapter\Noop
This is an "empty" or null adapter. It can be used for testing or any other purpose that no session needs to be invoked
<?php
use Phalcon\Session\Manager;
use Phalcon\Session\Adapter\Noop;
$session = new Manager();
$session->setAdapter(new Noop());
Phalcon\Session\Adapter\Noop— implementsSessionHandlerInterface,SessionUpdateTimestampHandlerInterface
Uses SessionHandlerInterface · SessionUpdateTimestampHandlerInterface
Method Summary¶
public bool close() Close public bool destroy( mixed $id ) Destroy public int|false gc( int $max_lifetime ) Garbage Collector public bool open(mixed $path,mixed $name) Open public string read( mixed $id ) Read public bool updateTimestamp(mixed $id,mixed $data) Refresh the session lifetime without changing the session data public bool validateId( mixed $id ) Validate the session id (used when strict mode is enabled) public bool write(mixed $id,mixed $data) Write Methods¶
close()¶
Close
destroy()¶
Destroy
gc()¶
Garbage Collector
open()¶
Open
read()¶
Read
updateTimestamp()¶
Refresh the session lifetime without changing the session data
validateId()¶
Validate the session id (used when strict mode is enabled)
write()¶
Write
Session\Adapter\Redis¶
Class Source on GitHub
Phalcon\Session\Adapter\Redis
Phalcon\Session\Adapter\AbstractAdapterPhalcon\Session\Adapter\Redis
Uses Phalcon\Session\Adapter\Exceptions\AdapterRuntimeError · Phalcon\Storage\AdapterFactory
Method Summary¶
public __construct(AdapterFactory $factory,array $options = []) Constructor public bool close() Close - releases the session lock if one is held public bool destroy( mixed $id ) Destroy public string read( mixed $id ) Read protected bool acquireLock( mixed $id ) Tries to acquire the session lock, pausing lockWaitTime microseconds protected void releaseLock() Releases the session lock - only when this instance still owns it Properties¶
protected bool $lockAcquired = false protected int $lockExpiry = 30 Lock time-to-live in seconds. The lock is not refreshed during the request: a request that runs longer than this expiry loses its lock silently and a concurrent request may then acquire it (the token-guarded release still avoids deleting the newer lock). Raise this above the longest expected request to retain the lock for the whole request. protected string $lockKey = "" protected int $lockRetries = 100 protected string $lockToken = "" protected int $lockWaitTime = 50000 protected bool $lockingEnabled = false protected string $prefix = "" Methods¶
__construct()¶
Constructor
close()¶
Close - releases the session lock if one is held
destroy()¶
Destroy
read()¶
Read
acquireLock()¶
Tries to acquire the session lock, pausing lockWaitTime microseconds between attempts, up to lockRetries times
releaseLock()¶
Releases the session lock - only when this instance still owns it
Session\Adapter\Stream¶
Class Source on GitHub
Phalcon\Session\Adapter\Stream
This is the file based adapter. It stores sessions in a file based system
<?php
use Phalcon\Session\Manager;
use Phalcon\Session\Adapter\Stream;
$session = new Manager();
$files = new Stream(
[
'savePath' => '/tmp',
]
);
$session->setAdapter($files);
@property array $options @property string $prefix @property string $path
Phalcon\Session\Adapter\NoopPhalcon\Session\Adapter\Stream
Uses Phalcon\Session\Adapter\Exceptions\AdapterRuntimeError · Phalcon\Session\Adapter\Exceptions\InvalidSavePath · Phalcon\Session\Adapter\Exceptions\SavePathUnavailable
Method Summary¶
public __construct( array $options = [] ) Constructor public bool destroy( mixed $id ) public int|false gc( int $max_lifetime ) Garbage Collector public bool open(mixed $path,mixed $name) Ignore the savePath and use local defined path public string read( mixed $id ) Reads data from the adapter public bool updateTimestamp(mixed $id,mixed $data) Refresh the session file modification time without changing its data public bool validateId( mixed $id ) Validate the session id (used when strict mode is enabled) public bool write(mixed $id,mixed $data) protected mixed getArrVal(array $collection,mixed $index,mixed $defaultValue = null,string $cast = null) @todo Remove this when we get traits protected array|false getGlobFiles( string $pattern ) Gets the glob array or returns false on failure protected string getPrefixedName( mixed $name ) Helper method to get the name prefixed protected phpFileExists( string $filename ) @link https://php.net/manual/en/function.file-exists.php protected phpFileGetContents( string $filename ) @link https://php.net/manual/en/function.file-get-contents.php protected phpFilePutContents(string $filename,mixed $data,int $flags = 0,mixed $context = null) @link https://php.net/manual/en/function.file-put-contents.php protected phpFopen(string $filename,string $mode) @link https://php.net/manual/en/function.fopen.php protected string phpIniGet( string $varname ) Gets the value of a configuration option protected bool phpIsWritable( string $filename ) Tells whether the filename is writable Properties¶
protected array $options = [] Session options protected string $prefix = "" Session prefix Methods¶
__construct()¶
Constructor
destroy()¶
gc()¶
Garbage Collector
open()¶
Ignore the savePath and use local defined path
read()¶
Reads data from the adapter
updateTimestamp()¶
Refresh the session file modification time without changing its data
validateId()¶
Validate the session id (used when strict mode is enabled)
write()¶
getArrVal()¶
protected function getArrVal(
array $collection,
mixed $index,
mixed $defaultValue = null,
string $cast = null
): mixed;
@todo Remove this when we get traits
getGlobFiles()¶
Gets the glob array or returns false on failure
getPrefixedName()¶
Helper method to get the name prefixed
phpFileExists()¶
@link https://php.net/manual/en/function.file-exists.php
phpFileGetContents()¶
@link https://php.net/manual/en/function.file-get-contents.php
phpFilePutContents()¶
protected function phpFilePutContents(
string $filename,
mixed $data,
int $flags = 0,
mixed $context = null
);
@link https://php.net/manual/en/function.file-put-contents.php
phpFopen()¶
@link https://php.net/manual/en/function.fopen.php
phpIniGet()¶
Gets the value of a configuration option
@link https://php.net/manual/en/function.ini-get.php @link https://php.net/manual/en/ini.list.php
phpIsWritable()¶
Tells whether the filename is writable
@link https://php.net/manual/en/function.is-writable.php
Session\Bag¶
Class Source on GitHub
Phalcon\Session\Bag
This component helps to separate session data into "namespaces". Working by this way you can easily create groups of session variables into the application
@property DiInterface|null $container @property string $name @property ManagerInterface $session;
Phalcon\Support\CollectionPhalcon\Session\Bag— implementsPhalcon\Session\BagInterface,Phalcon\Di\InjectionAwareInterface
Uses Phalcon\Di\Di · Phalcon\Di\DiInterface · Phalcon\Di\InjectionAwareInterface · Phalcon\Session\ManagerInterface · Phalcon\Support\Collection
Method Summary¶
public __construct(ManagerInterface $session,string $name) public void clear() Destroys the session bag public DiInterface getDI() Returns the DependencyInjector container public void init( array $data = [] ) Initialize internal array public void remove( string $element ) Removes a property from the internal bag public void set(string $element,mixed $value) Sets a value in the session bag public void setDI( DiInterface $container ) Sets the DependencyInjector container Methods¶
__construct()¶
clear()¶
Destroys the session bag
getDI()¶
Returns the DependencyInjector container
init()¶
Initialize internal array
remove()¶
Removes a property from the internal bag
set()¶
Sets a value in the session bag
setDI()¶
Sets the DependencyInjector container
Session\BagInterface¶
Interface Source on GitHub
Phalcon\Session\BagInterface
Interface for Phalcon\Session\Bag
Phalcon\Session\BagInterface
Method Summary¶
public mixed __get( string $element ) public bool __isset( string $element ) public void __set(string $element,mixed $value) public void __unset( string $element ) public void clear() public mixed get(string $element,mixed $defaultValue = null,string $cast = null) public bool has( string $element ) public void init( array $data = [] ) public void remove( string $element ) public void set(string $element,mixed $value) Methods¶
__get()¶
__isset()¶
__set()¶
__unset()¶
clear()¶
get()¶
has()¶
init()¶
remove()¶
set()¶
Session\Exception¶
Class Source on GitHub
Phalcon\Session\Exception
Exceptions thrown in Phalcon\Session will use this class
\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Adapter\Exceptions\AdapterRuntimeErrorPhalcon\Session\Adapter\Exceptions\InvalidSavePathPhalcon\Session\Adapter\Exceptions\SavePathUnavailablePhalcon\Session\Exceptions\InvalidSessionAdapterPhalcon\Session\Exceptions\InvalidSessionIdPhalcon\Session\Exceptions\InvalidSessionNamePhalcon\Session\Exceptions\SessionAlreadyStartedPhalcon\Session\Exceptions\SessionModificationDenied
Session\Exceptions\InvalidSessionAdapter¶
Class Source on GitHub
\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Exceptions\InvalidSessionAdapter
Uses Phalcon\Session\Exception
Method Summary¶
Methods¶
__construct()¶
Session\Exceptions\InvalidSessionId¶
Class Source on GitHub
\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Exceptions\InvalidSessionId
Uses Phalcon\Session\Exception
Method Summary¶
Methods¶
__construct()¶
Session\Exceptions\InvalidSessionName¶
Class Source on GitHub
\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Exceptions\InvalidSessionName
Uses Phalcon\Session\Exception
Method Summary¶
Methods¶
__construct()¶
Session\Exceptions\SessionAlreadyStarted¶
Class Source on GitHub
\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Exceptions\SessionAlreadyStarted
Uses Phalcon\Session\Exception
Method Summary¶
Methods¶
__construct()¶
Session\Exceptions\SessionModificationDenied¶
Class Source on GitHub
\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Exceptions\SessionModificationDenied
Uses Phalcon\Session\Exception
Method Summary¶
Methods¶
__construct()¶
Session\Manager¶
Class Source on GitHub
@property SessionHandlerInterface|null $adapter @property string $name @property array $options @property string $uniqueId
stdClassPhalcon\Di\AbstractInjectionAwarePhalcon\Session\Manager— implementsPhalcon\Session\ManagerInterface
Uses InvalidArgumentException · Phalcon\Di\AbstractInjectionAware · Phalcon\Di\DiInterface · Phalcon\Session\Exceptions\InvalidSessionAdapter · Phalcon\Session\Exceptions\InvalidSessionId · Phalcon\Session\Exceptions\InvalidSessionName · Phalcon\Session\Exceptions\SessionAlreadyStarted · Phalcon\Session\Exceptions\SessionModificationDenied · SessionHandlerInterface
Method Summary¶
public __construct( array $options = [] ) Manager constructor. public mixed __get( string $key ) Alias: Gets a session variable from an application context public bool __isset( string $key ) Alias: Check whether a session variable is set in an application context public void __set(string $key,mixed $value) Alias: Sets a session variable in an application context public void __unset( string $key ) Alias: Removes a session variable from an application context public void destroy() Destroy/end a session public bool exists() Check whether the session has been started public mixed get(string $key,mixed $defaultValue = null,bool $remove = false) Gets a session variable from an application context public SessionHandlerInterface|null getAdapter() Returns the stored session adapter public string getId() Returns the session id public string getName() Returns the name of the session public array getOptions() Get internal options public bool has( string $key ) Check whether a session variable is set in an application context public ManagerInterface regenerateId( bool $deleteOldSession = true ) Regenerates the session id via session_regenerate_id() (when the public void remove( string $key ) Removes a session variable from an application context public void set(string $key,mixed $value) Sets a session variable in an application context public ManagerInterface setAdapter( SessionHandlerInterface $adapter ) Set the adapter for the session public ManagerInterface setId( string $sessionId ) Set session Id public ManagerInterface setName( string $name ) Set the session name. Throw exception if the session has started public void setOptions( array $options ) Sets session's options public bool start() Starts the session (if headers are already sent the session will not be public int status() Returns the status of the current session. protected bool phpHeadersSent() Checks if or where headers have been sent Methods¶
__construct()¶
Manager constructor.
__get()¶
Alias: Gets a session variable from an application context
__isset()¶
Alias: Check whether a session variable is set in an application context
__set()¶
Alias: Sets a session variable in an application context
__unset()¶
Alias: Removes a session variable from an application context
destroy()¶
Destroy/end a session
exists()¶
Check whether the session has been started
get()¶
Gets a session variable from an application context
getAdapter()¶
Returns the stored session adapter
getId()¶
Returns the session id
getName()¶
Returns the name of the session
getOptions()¶
Get internal options
has()¶
Check whether a session variable is set in an application context
regenerateId()¶
Regenerates the session id via session_regenerate_id() (when the session is active). The registered save handler persists the data under the new id.
remove()¶
Removes a session variable from an application context
set()¶
Sets a session variable in an application context
setAdapter()¶
Set the adapter for the session
setId()¶
Set session Id
setName()¶
Set the session name. Throw exception if the session has started and do not allow poop names
setOptions()¶
Sets session's options
start()¶
Starts the session (if headers are already sent the session will not be started)
status()¶
Returns the status of the current session.
phpHeadersSent()¶
Checks if or where headers have been sent
@link https://php.net/manual/en/function.headers-sent.php
Session\ManagerInterface¶
Interface Source on GitHub
Phalcon\Session
Interface for the Phalcon\Session\Manager
Phalcon\Session\ManagerInterface
Uses InvalidArgumentException · SessionHandlerInterface
Method Summary¶
public mixed __get( string $key ) Alias: Gets a session variable from an application context public bool __isset( string $key ) Alias: Check whether a session variable is set in an application context public void __set(string $key,mixed $value) Alias: Sets a session variable in an application context public void __unset( string $key ) Alias: Removes a session variable from an application context public void destroy() Destroy/end a session public bool exists() Check whether the session has been started public mixed get(string $key,mixed $defaultValue = null,bool $remove = false) Gets a session variable from an application context public SessionHandlerInterface|null getAdapter() Returns the stored session adapter public string getId() Returns the session id public string getName() Returns the name of the session public array getOptions() Get internal options public bool has( string $key ) Check whether a session variable is set in an application context public ManagerInterface regenerateId( bool $deleteOldSession = true ) Regenerates the session id using the adapter. public void remove( string $key ) Removes a session variable from an application context public void set(string $key,mixed $value) Sets a session variable in an application context public ManagerInterface setAdapter( SessionHandlerInterface $adapter ) Set the adapter for the session public ManagerInterface setId( string $sessionId ) Set session Id public ManagerInterface setName( string $name ) Set the session name. Throw exception if the session has started public void setOptions( array $options ) Sets session's options public bool start() Starts the session (if headers are already sent the session will not be public int status() Returns the status of the current session. Constants¶
int SESSION_ACTIVE = 2 int SESSION_DISABLED = 0 int SESSION_NONE = 1 Methods¶
__get()¶
Alias: Gets a session variable from an application context
__isset()¶
Alias: Check whether a session variable is set in an application context
__set()¶
Alias: Sets a session variable in an application context
__unset()¶
Alias: Removes a session variable from an application context
destroy()¶
Destroy/end a session
exists()¶
Check whether the session has been started
get()¶
Gets a session variable from an application context
getAdapter()¶
Returns the stored session adapter
getId()¶
Returns the session id
getName()¶
Returns the name of the session
getOptions()¶
Get internal options
has()¶
Check whether a session variable is set in an application context
regenerateId()¶
Regenerates the session id using the adapter.
remove()¶
Removes a session variable from an application context
set()¶
Sets a session variable in an application context
setAdapter()¶
Set the adapter for the session
setId()¶
Set session Id
setName()¶
Set the session name. Throw exception if the session has started and do not allow poop names
setOptions()¶
Sets session's options
start()¶
Starts the session (if headers are already sent the session will not be started)
status()¶
Returns the status of the current session.