Skip to content

Phalcon session

NOTE

All classes are prefixed with Phalcon

Session\Adapter\AbstractAdapter Abstract

Source on GitHub

  • Namespace

    • Phalcon\Session\Adapter
  • Uses

    • Phalcon\Storage\Adapter\AdapterInterface
    • SessionHandlerInterface
  • Extends

  • Implements

    • SessionHandlerInterface

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Properties

/**
 * @var AdapterInterface
 */
protected $adapter;

Methods

public function close(): bool;
Close

public function destroy( mixed $id ): bool;
Destroy

public function gc( int $max_lifetime ): int | false;
Garbage Collector

public function open( mixed $path, mixed $name ): bool;
Open

public function read( mixed $id ): string;
Read

public function write( mixed $id, mixed $data ): bool;
Write

protected function getArrVal( array $collection, mixed $index, mixed $defaultValue = null ): mixed;
@todo Remove this when we get traits

Session\Adapter\Libmemcached

Source on GitHub

  • Namespace

    • Phalcon\Session\Adapter
  • Uses

    • Phalcon\Storage\AdapterFactory
  • Extends

    AbstractAdapter

  • Implements

Phalcon\Session\Adapter\Libmemcached

Methods

public function __construct( AdapterFactory $factory, array $options = [] );
Libmemcached constructor.

Session\Adapter\Noop

Source on GitHub

  • Namespace

    • Phalcon\Session\Adapter
  • Uses

    • SessionHandlerInterface
  • Extends

  • Implements

    • SessionHandlerInterface

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());

Properties

/**
 * The connection of some adapters
 *
 * @var null
 */
protected $connection;

/**
 * Session options
 *
 * @var array
 */
protected $options;

/**
 * Session prefix
 *
 * @var string
 */
protected $prefix = ;

/**
 * Time To Live
 *
 * @var int
 */
protected $ttl = 8600;

Methods

public function __construct( array $options = [] );
Constructor

public function close(): bool;
Close

public function destroy( mixed $id ): bool;
Destroy

public function gc( int $max_lifetime ): int | false;
Garbage Collector

public function open( mixed $path, mixed $name ): bool;
Open

public function read( mixed $id ): string;
Read

public function write( mixed $id, mixed $data ): bool;
Write

protected function getPrefixedName( mixed $name ): string;
Helper method to get the name prefixed

Session\Adapter\Redis

Source on GitHub

  • Namespace

    • Phalcon\Session\Adapter
  • Uses

    • Phalcon\Storage\AdapterFactory
  • Extends

    AbstractAdapter

  • Implements

Phalcon\Session\Adapter\Redis

Methods

public function __construct( AdapterFactory $factory, array $options = [] );
Constructor

Session\Adapter\Stream

Source on GitHub

  • Namespace

    • Phalcon\Session\Adapter
  • Uses

    • Phalcon\Session\Exception
  • Extends

    Noop

  • Implements

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

Properties

/**
 * @var string
 */
private $path = ;

Methods

public function __construct( array $options = [] );
Constructor

public function destroy( mixed $id ): bool;

public function gc( int $max_lifetime ): int | false;
Garbage Collector

public function open( mixed $path, mixed $name ): bool;
Ignore the savePath and use local defined path

public function read( mixed $id ): string;
Reads data from the adapter

public function write( mixed $id, mixed $data ): bool;

protected function getArrVal( array $collection, mixed $index, mixed $defaultValue = null, string $cast = null ): mixed;
@todo Remove this when we get traits

protected function phpFileExists( string $filename );
protected function phpFileGetContents( string $filename );
protected function phpFilePutContents( string $filename, mixed $data, int $flags = int, mixed $context = null );
protected function phpFopen( string $filename, string $mode );

protected function phpIniGet( string $varname ): string;
Gets the value of a configuration option

protected function phpIsWritable( string $filename ): bool;
Tells whether the filename is writable

Session\Bag

Source on GitHub

  • Namespace

    • Phalcon\Session
  • Uses

    • Phalcon\Di\Di
    • Phalcon\Di\DiInterface
    • Phalcon\Di\InjectionAwareInterface
    • Phalcon\Session\ManagerInterface
    • Phalcon\Support\Collection
  • Extends

    Collection

  • Implements

    • BagInterface
    • InjectionAwareInterface

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

$user = new \Phalcon\Session\Bag("user");

$user->name = "Kimbra Johnson";
$user->age  = 22;

@property DiInterface|null $container @property string $name @property ManagerInterface $session;

Properties

/**
 * @var DiInterface|null
 */
private $container;

/**
 * Session Bag name
 *
 * @var string
 */
private $name;

/**
 * @var ManagerInterface
 */
private $session;

Methods

public function __construct( ManagerInterface $session, string $name );

public function clear(): void;
Destroys the session bag

public function getDI(): DiInterface;
Returns the DependencyInjector container

public function init( array $data = [] ): void;
Initialize internal array

public function remove( string $element ): void;
Removes a property from the internal bag

public function set( string $element, mixed $value ): void;
Sets a value in the session bag

public function setDI( DiInterface $container ): void;
Sets the DependencyInjector container

Session\BagInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Session
  • Uses

  • Extends

  • Implements

Phalcon\Session\BagInterface

Interface for Phalcon\Session\Bag

Methods

public function __get( string $element ): mixed;
public function __isset( string $element ): bool;
public function __set( string $element, mixed $value ): void;
public function __unset( string $element ): void;
public function clear(): void;
public function get( string $element, mixed $defaultValue = null, string $cast = null ): mixed;
public function has( string $element ): bool;
public function init( array $data = [] ): void;
public function remove( string $element ): void;
public function set( string $element, mixed $value ): void;

Session\Exception

Source on GitHub

  • Namespace

    • Phalcon\Session
  • Uses

  • Extends

    \Exception

  • Implements

Phalcon\Session\Exception

Exceptions thrown in Phalcon\Session will use this class

Session\Manager

Source on GitHub

  • Namespace

    • Phalcon\Session
  • Uses

    • InvalidArgumentException
    • Phalcon\Di\AbstractInjectionAware
    • Phalcon\Di\DiInterface
    • Phalcon\Support\Helper\Arr\Get
    • RuntimeException
    • SessionHandlerInterface
  • Extends

    AbstractInjectionAware

  • Implements

    • ManagerInterface

@property SessionHandlerInterface|null $adapter @property string $name @property array $options @property string $uniqueId

Properties

/**
 * @var SessionHandlerInterface|null
 */
private $adapter;

/**
 * @var string
 */
private $name = ;

/**
 * @var array
 */
private $options;

/**
 * @var string
 */
private $uniqueId = ;

Methods

public function __construct( array $options = [] );
Manager constructor.

public function __get( string $key ): mixed;
Alias: Gets a session variable from an application context

public function __isset( string $key ): bool;
Alias: Check whether a session variable is set in an application context

public function __set( string $key, mixed $value ): void;
Alias: Sets a session variable in an application context

public function __unset( string $key ): void;
Alias: Removes a session variable from an application context

public function destroy(): void;
Destroy/end a session

public function exists(): bool;
Check whether the session has been started

public function get( string $key, mixed $defaultValue = null, bool $remove = bool ): mixed;
Gets a session variable from an application context

public function getAdapter(): SessionHandlerInterface;
Returns the stored session adapter

public function getId(): string;
Returns the session id

public function getName(): string;
Returns the name of the session

public function getOptions(): array;
Get internal options

public function has( string $key ): bool;
Check whether a session variable is set in an application context

public function regenerateId( bool $deleteOldSession = bool ): ManagerInterface;
Regenerates the session id using the adapter.

public function remove( string $key ): void;
Removes a session variable from an application context

public function set( string $key, mixed $value ): void;
Sets a session variable in an application context

public function setAdapter( SessionHandlerInterface $adapter ): ManagerInterface;
Set the adapter for the session

public function setId( string $sessionId ): ManagerInterface;
Set session Id

public function setName( string $name ): ManagerInterface;
Set the session name. Throw exception if the session has started and do not allow poop names

public function setOptions( array $options ): void;
Sets session's options

public function start(): bool;
Starts the session (if headers are already sent the session will not be started)

public function status(): int;
Returns the status of the current session.

protected function phpHeadersSent(): bool;
Checks if or where headers have been sent

Session\ManagerInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Session
  • Uses

    • InvalidArgumentException
    • RuntimeException
    • SessionHandlerInterface
  • Extends

  • Implements

Phalcon\Session

Interface for the Phalcon\Session\Manager

Constants

const SESSION_ACTIVE = 2;
const SESSION_DISABLED = 0;
const SESSION_NONE = 1;

Methods

public function __get( string $key ): mixed;
Alias: Gets a session variable from an application context

public function __isset( string $key ): bool;
Alias: Check whether a session variable is set in an application context

public function __set( string $key, mixed $value ): void;
Alias: Sets a session variable in an application context

public function __unset( string $key ): void;
Alias: Removes a session variable from an application context

public function destroy(): void;
Destroy/end a session

public function exists(): bool;
Check whether the session has been started

public function get( string $key, mixed $defaultValue = null, bool $remove = bool ): mixed;
Gets a session variable from an application context

public function getAdapter(): SessionHandlerInterface;
Returns the stored session adapter

public function getId(): string;
Returns the session id

public function getName(): string;
Returns the name of the session

public function getOptions(): array;
Get internal options

public function has( string $key ): bool;
Check whether a session variable is set in an application context

public function regenerateId( bool $deleteOldSession = bool ): ManagerInterface;
Regenerates the session id using the adapter.

public function remove( string $key ): void;
Removes a session variable from an application context

public function set( string $key, mixed $value ): void;
Sets a session variable in an application context

public function setAdapter( SessionHandlerInterface $adapter ): ManagerInterface;
Set the adapter for the session

public function setId( string $sessionId ): ManagerInterface;
Set session Id

public function setName( string $name ): ManagerInterface;
Set the session name. Throw exception if the session has started and do not allow poop names

@throws InvalidArgumentException

public function setOptions( array $options ): void;
Sets session's options

public function start(): bool;
Starts the session (if headers are already sent the session will not be started)

public function status(): int;
Returns the status of the current session.