Session\Adapter\AbstractAdapter
AbstractSource on GitHubPhalcon\Session\Adapter\AbstractAdapter- implements\SessionHandlerInterface,\SessionUpdateTimestampHandlerInterface
Uses Phalcon\Storage\Adapter\AdapterInterface · Phalcon\Traits\Support\Helper\Arr\GetTrait · SessionHandlerInterface · SessionUpdateTimestampHandlerInterface
Method Summary
publicboolclose()Close
publicbooldestroy(string $id)Destroy
publicfalse|intgc(int $max_lifetime)Garbage Collector
publicboolopen(string $path,string $name)Open
publicstringread(string $id)Read
publicboolupdateTimestamp(string $id,string $data)Refresh the session lifetime without changing the session data
publicboolvalidateId(string $id)Validate the session id (used when strict mode is enabled)
publicboolwrite(string $id,string $data)Write
Properties
protectedAdapterInterface$adapterMethods
close()
public function close(): bool;Close
destroy()
public function destroy( string $id ): bool;Destroy
gc()
public function gc( int $max_lifetime ): false|int;Garbage Collector
open()
public function open(
string $path,
string $name
): bool;Open
read()
public function read( string $id ): string;Read
updateTimestamp()
public function updateTimestamp(
string $id,
string $data
): bool;Refresh the session lifetime without changing the session data
validateId()
public function validateId( string $id ): bool;Validate the session id (used when strict mode is enabled)
write()
public function write(
string $id,
string $data
): bool;Write
Session\Adapter\Exceptions\AdapterRuntimeError
ClassSource on GitHub\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Adapter\Exceptions\AdapterRuntimeError
Uses Phalcon\Session\Exception
Session\Adapter\Exceptions\InvalidSavePath
ClassSource on GitHub\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Adapter\Exceptions\InvalidSavePath
Uses Phalcon\Session\Exception
Method Summary
Methods
__construct()
public function __construct();Session\Adapter\Exceptions\SavePathUnavailable
ClassSource on GitHub\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Adapter\Exceptions\SavePathUnavailable
Uses Phalcon\Session\Exception
Method Summary
Methods
__construct()
public function __construct( string $path );Session\Adapter\Libmemcached
ClassSource on GitHubPhalcon\Session\Adapter\Libmemcached
Phalcon\Session\Adapter\AbstractAdapterPhalcon\Session\Adapter\Libmemcached
Uses Exception · Phalcon\Contracts\Session\SessionTypes · Phalcon\Storage\AdapterFactory
Method Summary
Methods
__construct()
public function __construct(
AdapterFactory $factory,
array $options = []
);Libmemcached constructor.
] ], ‘defaultSerializer’ => ‘Php’, ‘lifetime’ => 3600, ‘serializer’ => null, ‘prefix’ => ‘sess-memc-’, ‘stripPrefix’ => false ]
Session\Adapter\Noop
ClassSource on GitHubPhalcon\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- implements\SessionHandlerInterface,\SessionUpdateTimestampHandlerInterface
Uses SessionHandlerInterface · SessionUpdateTimestampHandlerInterface
Method Summary
publicboolclose()Close
publicbooldestroy(string $id)Destroy
publicfalse|intgc(int $max_lifetime)Garbage Collector
publicboolopen(string $path,string $name)Open
publicstringread(string $id)Read
publicboolupdateTimestamp(string $id,string $data)Refresh the session lifetime without changing the session data
publicboolvalidateId(string $id)Validate the session id (used when strict mode is enabled)
publicboolwrite(string $id,string $data)Write
Methods
close()
public function close(): bool;Close
destroy()
public function destroy( string $id ): bool;Destroy
gc()
public function gc( int $max_lifetime ): false|int;Garbage Collector
open()
public function open(
string $path,
string $name
): bool;Open
read()
public function read( string $id ): string;Read
updateTimestamp()
public function updateTimestamp(
string $id,
string $data
): bool;Refresh the session lifetime without changing the session data
validateId()
public function validateId( string $id ): bool;Validate the session id (used when strict mode is enabled)
write()
public function write(
string $id,
string $data
): bool;Write
Session\Adapter\Redis
ClassSource on GitHubPhalcon\Session\Adapter\Redis
Phalcon\Session\Adapter\AbstractAdapterPhalcon\Session\Adapter\Redis
Uses Exception · Phalcon\Contracts\Session\SessionTypes · Phalcon\Session\Adapter\Exceptions\AdapterRuntimeError · Phalcon\Storage\AdapterFactory
Method Summary
public__construct(AdapterFactory $factory,array $options = [])Constructor
publicboolclose()Close - releases the session lock if one is held
publicbooldestroy(string $id)Destroy
publicstringread(string $id)Read
protectedboolacquireLock(string $id)Tries to acquire the session lock, pausing lockWaitTime microseconds
protectedvoidreleaseLock()Releases the session lock - only when this instance still owns it
Properties
protectedbool$lockAcquired = falseprotectedint$lockExpiry = 30Lock 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.
protectedstring$lockKey = ""protectedint$lockRetries = 100protectedstring$lockToken = ""protectedint$lockWaitTime = 50000protectedbool$lockingEnabled = falseprotectedstring$prefix = ""Methods
__construct()
public function __construct(
AdapterFactory $factory,
array $options = []
);Constructor
close()
public function close(): bool;Close - releases the session lock if one is held
destroy()
public function destroy( string $id ): bool;Destroy
read()
public function read( string $id ): string;Read
acquireLock()
protected function acquireLock( string $id ): bool;Tries to acquire the session lock, pausing lockWaitTime microseconds
between attempts, up to lockRetries times
releaseLock()
protected function releaseLock(): void;Releases the session lock - only when this instance still owns it
Session\Adapter\Stream
ClassSource on GitHubPhalcon\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);Phalcon\Session\Adapter\NoopPhalcon\Session\Adapter\Stream
Uses Phalcon\Contracts\Session\SessionTypes · Phalcon\Session\Adapter\Exceptions\AdapterRuntimeError · Phalcon\Session\Adapter\Exceptions\InvalidSavePath · Phalcon\Session\Adapter\Exceptions\SavePathUnavailable · Phalcon\Traits\Php\FileTrait · Phalcon\Traits\Php\IniTrait · Phalcon\Traits\Support\Helper\Arr\GetTrait · Phalcon\Traits\Support\Helper\Str\DirSeparatorTrait
Method Summary
public__construct(array $options = [])Constructor
publicbooldestroy(string $id)publicfalse|intgc(int $max_lifetime)Garbage Collector
publicboolopen(string $path,string $name)Ignore the savePath and use local defined path
publicstringread(string $id)Reads data from the adapter
publicboolupdateTimestamp(string $id,string $data)Refresh the session file modification time without changing its data
publicboolvalidateId(string $id)Validate the session id (used when strict mode is enabled)
publicboolwrite(string $id,string $data)protectedarray|falsegetGlobFiles(string $pattern)Gets the glob array or returns false on failure
protectedstringgetPrefixedName(mixed $name)Helper method to get the name prefixed
Properties
protectedarray$options = []Session options
protectedstring$prefix = ""Session prefix
Methods
__construct()
public function __construct( array $options = [] );Constructor
destroy()
public function destroy( string $id ): bool;gc()
public function gc( int $max_lifetime ): false|int;Garbage Collector
open()
public function open(
string $path,
string $name
): bool;Ignore the savePath and use local defined path
read()
public function read( string $id ): string;Reads data from the adapter
updateTimestamp()
public function updateTimestamp(
string $id,
string $data
): bool;Refresh the session file modification time without changing its data
validateId()
public function validateId( string $id ): bool;Validate the session id (used when strict mode is enabled)
write()
public function write(
string $id,
string $data
): bool;getGlobFiles()
protected function getGlobFiles( string $pattern ): array|false;Gets the glob array or returns false on failure
getPrefixedName()
protected function getPrefixedName( mixed $name ): string;Helper method to get the name prefixed
Session\Bag
ClassSource on GitHubThis component helps to separate session data into “namespaces”. Working by this way you can easily create groups of session variables into the application
$user = new \Phalcon\Session\Bag("user");
$user->name = "Kimbra Johnson";
$user->age = 22;@property DiInterface|null $container @property string $name @property ManagerInterface $session;
@extends Collection<mixed>
Phalcon\Support\CollectionPhalcon\Session\Bag- implementsPhalcon\Session\BagInterface,Phalcon\Di\InjectionAwareInterface
Uses Phalcon\Contracts\Session\SessionTypes · Phalcon\Di\Di · Phalcon\Di\DiInterface · Phalcon\Di\InjectionAwareInterface · Phalcon\Session\ManagerInterface · Phalcon\Support\Collection
Method Summary
public__construct(ManagerInterface $session,string $name)publicvoidclear()Destroys the session bag
publicDiInterfacegetDI()Returns the DependencyInjector container
publicvoidinit(array $data = [])Initialize internal array
publicvoidremove(string $element)Removes a property from the internal bag
publicvoidset(string $element,mixed $value)Sets a value in the session bag
publicvoidsetDI(DiInterface $container)Sets the DependencyInjector container
Methods
__construct()
public function __construct(
ManagerInterface $session,
string $name
);clear()
public function clear(): void;Destroys the session bag
getDI()
public function getDI(): DiInterface;Returns the DependencyInjector container
init()
public function init( array $data = [] ): void;Initialize internal array
remove()
public function remove( string $element ): void;Removes a property from the internal bag
set()
public function set(
string $element,
mixed $value
): void;Sets a value in the session bag
setDI()
public function setDI( DiInterface $container ): void;Sets the DependencyInjector container
Session\BagInterface
InterfaceSource on GitHubInterface for Phalcon\Session\Bag
Phalcon\Session\BagInterface
Method Summary
publicmixed__get(string $element)publicbool__isset(string $element)publicvoid__set(string $element,mixed $value)publicvoid__unset(string $element)publicvoidclear()publicmixedget(string $element,mixed $defaultValue = null,string|null $cast = null)publicboolhas(string $element)publicvoidinit(array $data = [])publicvoidremove(string $element)publicvoidset(string $element,mixed $value)Methods
__get()
public function __get( string $element ): mixed;__isset()
public function __isset( string $element ): bool;__set()
public function __set(
string $element,
mixed $value
): void;__unset()
public function __unset( string $element ): void;clear()
public function clear(): void;get()
public function get(
string $element,
mixed $defaultValue = null,
string|null $cast = null
): mixed;has()
public function has( string $element ): bool;init()
public function init( array $data = [] ): void;remove()
public function remove( string $element ): void;set()
public function set(
string $element,
mixed $value
): void;Session\Exception
ClassSource on GitHubPhalcon\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
ClassSource on GitHub\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Exceptions\InvalidSessionAdapter
Uses Phalcon\Session\Exception
Method Summary
Methods
__construct()
public function __construct();Session\Exceptions\InvalidSessionId
ClassSource on GitHub\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Exceptions\InvalidSessionId
Uses Phalcon\Session\Exception
Method Summary
Methods
__construct()
public function __construct();Session\Exceptions\InvalidSessionName
ClassSource on GitHub\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Exceptions\InvalidSessionName
Uses Phalcon\Session\Exception
Method Summary
Methods
__construct()
public function __construct();Session\Exceptions\SessionAlreadyStarted
ClassSource on GitHub\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Exceptions\SessionAlreadyStarted
Uses Phalcon\Session\Exception
Method Summary
Methods
__construct()
public function __construct();Session\Exceptions\SessionModificationDenied
ClassSource on GitHub\ExceptionPhalcon\Session\ExceptionPhalcon\Session\Exceptions\SessionModificationDenied
Uses Phalcon\Session\Exception
Method Summary
Methods
__construct()
public function __construct();Session\Manager
ClassSource on GitHubSession manager class
\stdClassPhalcon\Di\AbstractInjectionAwarePhalcon\Session\Manager- implementsPhalcon\Session\ManagerInterface
Uses InvalidArgumentException · Phalcon\Contracts\Session\SessionTypes · 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 · Phalcon\Traits\Php\HeaderTrait · Phalcon\Traits\Support\Helper\Arr\GetTrait · SessionHandlerInterface
Method Summary
public__construct(array $options = [])Manager constructor.
publicmixed__get(string $key)Alias: Gets a session variable from an application context
publicbool__isset(string $key)Alias: Check whether a session variable is set in an application context
publicvoid__set(string $key,mixed $value)Alias: Sets a session variable in an application context
publicvoid__unset(string $key)Alias: Removes a session variable from an application context
publicvoiddestroy()Destroy/end a session
publicboolexists()Check whether the session has been started
publicmixedget(string $key,mixed $defaultValue = null,bool $remove = false)Gets a session variable from an application context
publicSessionHandlerInterface|nullgetAdapter()Returns the stored session adapter
publicstringgetId()Returns the session id
publicstringgetName()Returns the name of the session
publicarraygetOptions()Get internal options
publicboolhas(string $key)Check whether a session variable is set in an application context
publicManagerInterfaceregenerateId(bool $deleteOldSession = true)Regenerates the session id via session_regenerate_id() (when the
publicvoidremove(string $key)Removes a session variable from an application context
publicvoidset(string $key,mixed $value)Sets a session variable in an application context
publicManagerInterfacesetAdapter(SessionHandlerInterface $adapter)Set the adapter for the session
publicManagerInterfacesetId(string $sessionId)Set session Id
publicManagerInterfacesetName(string $name)Set the session name. Throw exception if the session has started
publicvoidsetOptions(array $options)Sets session’s options
publicboolstart()Starts the session (if headers are already sent the session will not be
publicintstatus()Returns the status of the current session.
Methods
__construct()
public function __construct( array $options = [] );Manager constructor.
__get()
public function __get( string $key ): mixed;Alias: Gets a session variable from an application context
__isset()
public function __isset( string $key ): bool;Alias: Check whether a session variable is set in an application context
__set()
public function __set(
string $key,
mixed $value
): void;Alias: Sets a session variable in an application context
__unset()
public function __unset( string $key ): void;Alias: Removes a session variable from an application context
destroy()
public function destroy(): void;Destroy/end a session
exists()
public function exists(): bool;Check whether the session has been started
get()
public function get(
string $key,
mixed $defaultValue = null,
bool $remove = false
): mixed;Gets a session variable from an application context
getAdapter()
public function getAdapter(): SessionHandlerInterface|null;Returns the stored session adapter
getId()
public function getId(): string;Returns the session id
getName()
public function getName(): string;Returns the name of the session
getOptions()
public function getOptions(): array;Get internal options
has()
public function has( string $key ): bool;Check whether a session variable is set in an application context
regenerateId()
public function regenerateId( bool $deleteOldSession = true ): ManagerInterface;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()
public function remove( string $key ): void;Removes a session variable from an application context
set()
public function set(
string $key,
mixed $value
): void;Sets a session variable in an application context
setAdapter()
public function setAdapter( SessionHandlerInterface $adapter ): ManagerInterface;Set the adapter for the session
setId()
public function setId( string $sessionId ): ManagerInterface;Set session Id
setName()
public function setName( string $name ): ManagerInterface;Set the session name. Throw exception if the session has started and do not allow poop names
setOptions()
public function setOptions( array $options ): void;Sets session’s options
start()
public function start(): bool;Starts the session (if headers are already sent the session will not be started)
status()
public function status(): int;Returns the status of the current session.
Session\ManagerInterface
InterfaceSource on GitHubInterface for the Phalcon\Session\Manager
Phalcon\Session\ManagerInterface
Uses InvalidArgumentException · Phalcon\Contracts\Session\SessionTypes · SessionHandlerInterface
Method Summary
publicmixed__get(string $key)Alias: Gets a session variable from an application context
publicbool__isset(string $key)Alias: Check whether a session variable is set in an application context
publicvoid__set(string $key,mixed $value)Alias: Sets a session variable in an application context
publicvoid__unset(string $key)Alias: Removes a session variable from an application context
publicvoiddestroy()Destroy/end a session
publicboolexists()Check whether the session has been started
publicmixedget(string $key,mixed $defaultValue = null,bool $remove = false)Gets a session variable from an application context
publicSessionHandlerInterface|nullgetAdapter()Returns the stored session adapter
publicstringgetId()Returns the session id
publicstringgetName()Returns the name of the session
publicarraygetOptions()Get internal options
publicboolhas(string $key)Check whether a session variable is set in an application context
publicManagerInterfaceregenerateId(bool $deleteOldSession = true)Regenerates the session id using the adapter.
publicvoidremove(string $key)Removes a session variable from an application context
publicvoidset(string $key,mixed $value)Sets a session variable in an application context
publicManagerInterfacesetAdapter(SessionHandlerInterface $adapter)Set the adapter for the session
publicManagerInterfacesetId(string $sessionId)Set session Id
publicManagerInterfacesetName(string $name)Set the session name. Throw exception if the session has started
publicvoidsetOptions(array $options)Sets session’s options
publicboolstart()Starts the session (if headers are already sent the session will not be
publicintstatus()Returns the status of the current session.
Constants
intSESSION_ACTIVE = 2intSESSION_DISABLED = 0intSESSION_NONE = 1Methods
__get()
public function __get( string $key ): mixed;Alias: Gets a session variable from an application context
__isset()
public function __isset( string $key ): bool;Alias: Check whether a session variable is set in an application context
__set()
public function __set(
string $key,
mixed $value
): void;Alias: Sets a session variable in an application context
__unset()
public function __unset( string $key ): void;Alias: Removes a session variable from an application context
destroy()
public function destroy(): void;Destroy/end a session
exists()
public function exists(): bool;Check whether the session has been started
get()
public function get(
string $key,
mixed $defaultValue = null,
bool $remove = false
): mixed;Gets a session variable from an application context
getAdapter()
public function getAdapter(): SessionHandlerInterface|null;Returns the stored session adapter
getId()
public function getId(): string;Returns the session id
getName()
public function getName(): string;Returns the name of the session
getOptions()
public function getOptions(): array;Get internal options
has()
public function has( string $key ): bool;Check whether a session variable is set in an application context
regenerateId()
public function regenerateId( bool $deleteOldSession = true ): ManagerInterface;Regenerates the session id using the adapter.
remove()
public function remove( string $key ): void;Removes a session variable from an application context
set()
public function set(
string $key,
mixed $value
): void;Sets a session variable in an application context
setAdapter()
public function setAdapter( SessionHandlerInterface $adapter ): ManagerInterface;Set the adapter for the session
setId()
public function setId( string $sessionId ): ManagerInterface;Set session Id
setName()
public function setName( string $name ): ManagerInterface;Set the session name. Throw exception if the session has started and do not allow poop names
setOptions()
public function setOptions( array $options ): void;Sets session’s options
start()
public function start(): bool;Starts the session (if headers are already sent the session will not be started)
status()
public function status(): int;Returns the status of the current session.