Skip to content

Phalcon storage

NOTE

All classes are prefixed with Phalcon

Storage\Adapter\AbstractAdapter Abstract

Source on GitHub

  • Namespace

    • Phalcon\Storage\Adapter
  • Uses

    • DateInterval
    • DateTime
    • Exception
    • Phalcon\Storage\SerializerFactory
    • Phalcon\Storage\Serializer\SerializerInterface
    • Phalcon\Support\Exception
  • Extends

  • Implements

    • AdapterInterface
    • Phalcon\Events\EventsAwareInterface

Class AbstractAdapter

@package Phalcon\Storage\Adapter

@property mixed $adapter @property string $defaultSerializer @property int $lifetime @property array $options @property string $prefix @property SerializerInterface $serializer @property SerializerFactory $serializerFactory

Properties

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

/**
 * Name of the default serializer class
 *
 * @var string
 */
protected $defaultSerializer = php;

/**
 * Name of the default TTL (time to live)
 *
 * @var int
 */
protected $lifetime = 3600;

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

/**
 * @var string
 */
protected $prefix = ph-memo-;

/**
 * Serializer
 *
 * @var SerializerInterface|null
 */
protected $serializer;

/**
 * Serializer Factory
 *
 * @var SerializerFactory
 */
protected $serializerFactory;

Methods

protected function __construct( SerializerFactory $factory, array $options = [] );
AbstractAdapter constructor.

abstract public function clear(): bool;
Flushes/clears the cache

abstract public function decrement( string $key, int $value = int ): int | bool;
Decrements a stored number

abstract public function delete( string $key ): bool;
Deletes data from the adapter

public function get( string $key, mixed $defaultValue = null ): mixed;
Reads data from the adapter

public function getAdapter(): mixed;
Returns the adapter - connects to the storage if not connected

public function getDefaultSerializer(): string;
Name of the default serializer class

abstract public function getKeys( string $prefix = string ): array;
Returns all the keys stored

public function getPrefix(): string;
Returns the prefix

abstract public function has( string $key ): bool;
Checks if an element exists in the cache

abstract public function increment( string $key, int $value = int ): int | bool;
Increments a stored number

abstract public function set( string $key, mixed $value, mixed $ttl = null ): bool;
Stores data in the adapter

public function setDefaultSerializer( string $serializer ): void;
protected function doGet( string $key );

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

protected function getFilteredKeys( mixed $keys, string $prefix ): array;
Filters the keys array based on global and passed prefix

protected function getPrefixedKey( mixed $key ): string;
Returns the key requested, prefixed

protected function getSerializedData( mixed $content ): mixed;
Returns serialized data

protected function getTtl( mixed $ttl ): int;
Calculates the TTL for a cache item

protected function getUnserializedData( mixed $content, mixed $defaultValue = null ): mixed;
Returns unserialized data

protected function initSerializer(): void;
Initializes the serializer

@throws SupportException

Storage\Adapter\AdapterInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Storage\Adapter
  • Uses

    • Phalcon\Storage\Serializer\SerializerInterface
  • Extends

  • Implements

Interface for Phalcon\Logger adapters

Methods

public function clear(): bool;
Flushes/clears the cache

public function decrement( string $key, int $value = int ): int | bool;
Decrements a stored number

public function delete( string $key ): bool;
Deletes data from the adapter

public function get( string $key, mixed $defaultValue = null ): mixed;
Reads data from the adapter

public function getAdapter(): mixed;
Returns the already connected adapter or connects to the backend server(s)

public function getKeys( string $prefix = string ): array;
Returns all the keys stored

public function getPrefix(): string;
Returns the prefix for the keys

public function has( string $key ): bool;
Checks if an element exists in the cache

public function increment( string $key, int $value = int ): int | bool;
Increments a stored number

public function set( string $key, mixed $value, mixed $ttl = null ): bool;
Stores data in the adapter. If the TTL is null (default) or not defined then the default TTL will be used, as set in this adapter. If the TTL is 0 or a negative number, a delete() will be issued, since this item has expired. If you need to set this key forever, you should use the setForever() method.

public function setForever( string $key, mixed $value ): bool;
Stores data in the adapter forever. The key needs to manually deleted from the adapter.

Storage\Adapter\Apcu

Source on GitHub

  • Namespace

    • Phalcon\Storage\Adapter
  • Uses

    • APCUIterator
    • DateInterval
    • Exception
    • Phalcon\Storage\SerializerFactory
    • Phalcon\Support\Exception
  • Extends

    AbstractAdapter

  • Implements

Apcu adapter

@property array $options

Properties

/**
 * @var string
 */
protected $prefix = ph-apcu-;

Methods

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

public function clear(): bool;
Flushes/clears the cache

public function decrement( string $key, int $value = int ): int | bool;
Decrements a stored number

public function delete( string $key ): bool;
Reads data from the adapter

public function getKeys( string $prefix = string ): array;
Stores data in the adapter

public function has( string $key ): bool;
Checks if an element exists in the cache

public function increment( string $key, int $value = int ): int | bool;
Increments a stored number

public function set( string $key, mixed $value, mixed $ttl = null ): bool;
Stores data in the adapter. If the TTL is null (default) or not defined then the default TTL will be used, as set in this adapter. If the TTL is 0 or a negative number, a delete() will be issued, since this item has expired. If you need to set this key forever, you should use the setForever() method.

public function setForever( string $key, mixed $value ): bool;
Stores data in the adapter forever. The key needs to manually deleted from the adapter.

protected function doGet( string $key );

protected function phpApcuDec( mixed $key, int $step = int ): bool | int;
@todo Remove the below once we get traits

protected function phpApcuDelete( mixed $key ): bool | array;
protected function phpApcuExists( mixed $key ): bool | array;
protected function phpApcuFetch( mixed $key ): mixed;
protected function phpApcuInc( mixed $key, int $step = int ): bool | int;
protected function phpApcuIterator( string $pattern ): APCUIterator | bool;
protected function phpApcuStore( mixed $key, mixed $payload, int $ttl = int ): bool | array;

Storage\Adapter\Libmemcached

Source on GitHub

  • Namespace

    • Phalcon\Storage\Adapter
  • Uses

    • DateInterval
    • Exception
    • Phalcon\Storage\Exception
    • Phalcon\Storage\SerializerFactory
    • Phalcon\Support\Exception
  • Extends

    AbstractAdapter

  • Implements

Libmemcached adapter

Properties

/**
 * @var string
 */
protected $prefix = ph-memc-;

Methods

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

public function clear(): bool;
Flushes/clears the cache

public function decrement( string $key, int $value = int ): int | bool;
Decrements a stored number

public function delete( string $key ): bool;
Reads data from the adapter

public function getAdapter(): mixed;
Returns the already connected adapter or connects to the Memcached server(s)

public function getKeys( string $prefix = string ): array;
Stores data in the adapter

public function has( string $key ): bool;
Checks if an element exists in the cache

public function increment( string $key, int $value = int ): int | bool;
Increments a stored number

public function set( string $key, mixed $value, mixed $ttl = null ): bool;
Stores data in the adapter. If the TTL is null (default) or not defined then the default TTL will be used, as set in this adapter. If the TTL is 0 or a negative number, a delete() will be issued, since this item has expired. If you need to set this key forever, you should use the setForever() method.

public function setForever( string $key, mixed $value ): bool;
Stores data in the adapter forever. The key needs to manually deleted from the adapter.

Storage\Adapter\Memory

Source on GitHub

  • Namespace

    • Phalcon\Storage\Adapter
  • Uses

    • DateInterval
    • Exception
    • Phalcon\Storage\SerializerFactory
    • Phalcon\Support\Exception
  • Extends

    AbstractAdapter

  • Implements

Memory adapter

@property array $data @property array $options

Properties

/**
 * @var array
 */
protected $data;

Methods

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

public function clear(): bool;
Flushes/clears the cache

public function decrement( string $key, int $value = int ): int | bool;
Decrements a stored number

public function delete( string $key ): bool;
Deletes data from the adapter

public function getKeys( string $prefix = string ): array;
Stores data in the adapter

public function has( string $key ): bool;
Checks if an element exists in the cache

public function increment( string $key, int $value = int ): int | bool;
Increments a stored number

public function set( string $key, mixed $value, mixed $ttl = null ): bool;
Stores data in the adapter. If the TTL is null (default) or not defined then the default TTL will be used, as set in this adapter. If the TTL is 0 or a negative number, a delete() will be issued, since this item has expired. If you need to set this key forever, you should use the setForever() method.

public function setForever( string $key, mixed $value ): bool;
Stores data in the adapter forever. The key needs to manually deleted from the adapter.

protected function doGet( string $key );

Storage\Adapter\Redis

Source on GitHub

  • Namespace

    • Phalcon\Storage\Adapter
  • Uses

    • DateInterval
    • Exception
    • Phalcon\Storage\Exception
    • Phalcon\Storage\SerializerFactory
    • Phalcon\Support\Exception
  • Extends

    AbstractAdapter

  • Implements

Redis adapter

@property array $options

Properties

/**
 * @var string
 */
protected $prefix = ph-reds-;

Methods

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

public function clear(): bool;
Flushes/clears the cache

public function decrement( string $key, int $value = int ): int | bool;
Decrements a stored number

public function delete( string $key ): bool;
Reads data from the adapter

public function getAdapter(): mixed;
Returns the already connected adapter or connects to the Redis server(s)

public function getKeys( string $prefix = string ): array;
Stores data in the adapter

public function has( string $key ): bool;
Checks if an element exists in the cache

public function increment( string $key, int $value = int ): int | bool;
Increments a stored number

public function set( string $key, mixed $value, mixed $ttl = null ): bool;
Stores data in the adapter. If the TTL is null (default) or not defined then the default TTL will be used, as set in this adapter. If the TTL is 0 or a negative number, a delete() will be issued, since this item has expired. If you need to set this key forever, you should use the setForever() method.

public function setForever( string $key, mixed $value ): bool;
Stores data in the adapter forever. The key needs to manually deleted from the adapter.

Storage\Adapter\Stream

Source on GitHub

  • Namespace

    • Phalcon\Storage\Adapter
  • Uses

    • DateInterval
    • FilesystemIterator
    • Iterator
    • Phalcon\Storage\Exception
    • Phalcon\Storage\SerializerFactory
    • Phalcon\Storage\Traits\StorageErrorHandlerTrait
    • Phalcon\Support\Exception
    • RecursiveDirectoryIterator
    • RecursiveIteratorIterator
  • Extends

    AbstractAdapter

  • Implements

Stream adapter

@property string $storageDir @property array $options

Properties

/**
 * @var string
 */
protected $prefix = ph-strm;

/**
 * @var string
 */
protected $storageDir = ;

Methods

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

public function clear(): bool;
Flushes/clears the cache

public function decrement( string $key, int $value = int ): int | bool;
Decrements a stored number

public function delete( string $key ): bool;
Reads data from the adapter

public function get( string $key, mixed $defaultValue = null ): mixed;
Reads data from the adapter

public function getKeys( string $prefix = string ): array;
Stores data in the adapter

public function has( string $key ): bool;
Checks if an element exists in the cache and is not expired

public function increment( string $key, int $value = int ): int | bool;
Increments a stored number

public function set( string $key, mixed $value, mixed $ttl = null ): bool;
Stores data in the adapter. If the TTL is null (default) or not defined then the default TTL will be used, as set in this adapter. If the TTL is 0 or a negative number, a delete() will be issued, since this item has expired. If you need to set this key forever, you should use the setForever() method.

public function setForever( string $key, mixed $value ): bool;
Stores data in the adapter forever. The key needs to manually deleted from the adapter.

protected function phpFileExists( string $filename ): bool;
@todo Remove the methods below when we get traits

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

Storage\Adapter\Weak

Source on GitHub

  • Namespace

    • Phalcon\Storage\Adapter
  • Uses

    • DateInterval
    • Exception
    • Phalcon\Storage\SerializerFactory
    • Phalcon\Storage\Serializer\SerializerInterface
    • Phalcon\Support\Exception
  • Extends

    AbstractAdapter

  • Implements

  • Weak Adapter */

Properties

/**
 *
 *
 * @var int|null
 */
protected $fetching;

/**
 * @var array
 */
protected $weakList;

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

Methods

public function __construct( SerializerFactory $factory, array $options = [] );
Constructor, there are no options

public function clear(): bool;
Flushes/clears the cache

public function decrement( string $key, int $value = int ): int | bool;
Decrements a stored number

public function delete( string $key ): bool;
Deletes data from the adapter

public function get( string $key, mixed $defaultValue = null ): mixed;
Reads data from the adapter

public function getKeys( string $prefix = string ): array;
Stores data in the adapter

public function has( string $key ): bool;
Checks if an element exists in the cache

public function increment( string $key, int $value = int ): int | bool;
Increments a stored number

public function set( string $key, mixed $value, mixed $ttl = null ): bool;
Stores data in the adapter. If the TTL is null (default) or not defined then the default TTL will be used, as set in this adapter. If the TTL is 0 or a negative number, a delete() will be issued, since this item has expired. If you need to set this key forever, you should use the setForever() method.

public function setDefaultSerializer( string $serializer ): void;
will never set a serializer, WeakReference cannot be serialized

public function setForever( string $key, mixed $value ): bool;
For compatiblity only, there is no Forever with WeakReference.

Storage\AdapterFactory

Source on GitHub

  • Namespace

    • Phalcon\Storage
  • Uses

    • Phalcon\Factory\AbstractFactory
    • Phalcon\Storage\Adapter\AdapterInterface
  • Extends

    AbstractFactory

  • Implements

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.txt file that was distributed with this source code.

Properties

/**
 * @var SerializerFactory
 */
private $serializerFactory;

Methods

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

public function newInstance( string $name, array $options = [] ): AdapterInterface;
Create a new instance of the adapter

protected function getExceptionClass(): string;

protected function getServices(): array;
Returns the available adapters

Storage\Exception

Source on GitHub

  • Namespace

    • Phalcon\Storage
  • Uses

  • Extends

    \Exception

  • Implements

Phalcon\Storage\Exception

Exceptions thrown in Phalcon\Storage will use this class

Storage\Serializer\AbstractSerializer Abstract

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

  • Extends

  • Implements

    • SerializerInterface

@property mixed $data @property bool $isSuccess

Properties

/**
 * @var mixed
 */
protected $data;

/**
 * @var bool
 */
protected $isSuccess = true;

Methods

public function __construct( mixed $data = null );
AbstractSerializer constructor.

public function __serialize(): array;
Serialize data

public function __unserialize( array $data ): void;
Unserialize data

public function getData();

public function isSuccess(): bool;
Returns true if the serialize/unserialize operation was successful; false otherwise

public function setData( mixed $data ): void;

protected function isSerializable( mixed $data ): bool;
If this returns true, then the data is returned as is

Storage\Serializer\Base64

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

    • InvalidArgumentException
  • Extends

    AbstractSerializer

  • Implements

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.txt file that was distributed with this source code.

Methods

public function serialize(): string;
Serializes data

public function unserialize( mixed $data ): void;
Unserializes data

protected function phpBase64Decode( string $input, bool $strict = bool );
Wrapper for base64_decode

Storage\Serializer\Igbinary

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

  • Extends

    AbstractSerializer

  • Implements

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.txt file that was distributed with this source code.

Methods

public function serialize();
Serializes data

public function unserialize( mixed $data ): void;
Unserializes data

protected function doSerialize( mixed $value ): string | null;
Serialize

protected function doUnserialize( mixed $value );
Unserialize

protected function phpIgbinarySerialize( mixed $value ): string | null;
Wrapper for igbinary_serialize

Storage\Serializer\Json

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

    • InvalidArgumentException
    • JsonSerializable
    • Phalcon\Support\Helper\Json\Decode
    • Phalcon\Support\Helper\Json\Encode
  • Extends

    AbstractSerializer

  • Implements

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.txt file that was distributed with this source code.

Properties

/**
 * @var Decode
 */
private $decode;

/**
 * @var Encode
 */
private $encode;

Methods

public function __construct( mixed $data = null );
AbstractSerializer constructor.

public function serialize();
Serializes data

public function unserialize( mixed $data ): void;
Unserializes data

Storage\Serializer\MemcachedIgbinary

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

  • Extends

    None

  • Implements

Serializer using the built-in Memcached 'igbinary' serializer

Storage\Serializer\MemcachedJson

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

  • Extends

    None

  • Implements

Serializer using the built-in Memcached 'json' serializer

Storage\Serializer\MemcachedPhp

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

  • Extends

    None

  • Implements

Serializer using the built-in Memcached 'php' serializer

Storage\Serializer\Msgpack

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

  • Extends

    Igbinary

  • Implements

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.txt file that was distributed with this source code.

Methods

protected function doSerialize( mixed $value ): string;
Serializes data

protected function doUnserialize( mixed $value );

Storage\Serializer\None

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

  • Extends

    AbstractSerializer

  • Implements

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.txt file that was distributed with this source code.

Methods

public function serialize(): mixed;
Serializes data

public function unserialize( mixed $data ): void;
Unserializes data

Storage\Serializer\Php

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

    • InvalidArgumentException
  • Extends

    AbstractSerializer

  • Implements

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.txt file that was distributed with this source code.

Methods

public function serialize(): string;
Serializes data

public function unserialize( mixed $data ): void;
Unserializes data

Storage\Serializer\RedisIgbinary

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

  • Extends

    None

  • Implements

Serializer using the built-in Redis 'igbinary' serializer

Storage\Serializer\RedisJson

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

  • Extends

    None

  • Implements

Serializer using the built-in Redis 'json' serializer

Storage\Serializer\RedisMsgpack

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

  • Extends

    None

  • Implements

Serializer using the built-in Redis 'msgpack' serializer

Storage\Serializer\RedisNone

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

  • Extends

    None

  • Implements

Serializer using the built-in Redis 'none' serializer

Storage\Serializer\RedisPhp

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

  • Extends

    None

  • Implements

Serializer using the built-in Redis 'php' serializer

Storage\Serializer\SerializerInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Storage\Serializer
  • Uses

    • Serializable
  • Extends

    Serializable

  • Implements

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.txt file that was distributed with this source code.

Methods

public function getData(): mixed;
public function setData( mixed $data ): void;

Storage\SerializerFactory

Source on GitHub

  • Namespace

    • Phalcon\Storage
  • Uses

    • Phalcon\Factory\AbstractFactory
    • Phalcon\Storage\Serializer\SerializerInterface
  • Extends

    AbstractFactory

  • Implements

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.txt file that was distributed with this source code.

Methods

public function __construct( array $services = [] );
SerializerFactory constructor.

public function newInstance( string $name ): SerializerInterface;
protected function getExceptionClass(): string;

protected function getServices(): array;
Returns the available adapters