Final Class Phalcon\Registry
Código fuente en GitHub
Namespace |
Phalcon |
|
Uses |
Traversable |
|
Extends |
Collection |
Phalcon\Registry
Un registro es un contenedor para almacenar objetos y valores en el espacio de la aplicación. Al almacenar el valor en un registro, el mismo objeto siempre está disponible en toda la aplicación.
$registry = new \Phalcon\Registry();
// Set value
$registry->something = "something";
// or
$registry["something"] = "something";
// Get value
$value = $registry->something;
// or
$value = $registry["something"];
// Check if the key exists
$exists = isset($registry->something);
// or
$exists = isset($registry["something"]);
// Unset
unset($registry->something);
// or
unset($registry["something"]);
Además de ArrayAccess, Phalcon\Registry también implementa los interfaces Countable (count ($registry) devolverá la cantidad de elementos en el registro), Serializable e Iterator (puede iterar sobre el registro utilizando un bucle foreach). Para PHP 5.4 y superior, se implementa la interfaz JsonSerializable.
Phalcon\Registry es muy rápido (generalmente es más rápido que cualquier implementación del registro en el espacio de usuario); sin embargo, esto tiene un precio: Phalcon\Registry es una clase final y no se puede heredar.
Though Phalcon\Registry exposes methods like __get(), offsetGet(), count() etc, it is not recommended to invoke them manually (these methods exist mainly to match the interfaces the registry implements): $registry->__get(“property”) is several times slower than $registry->property.
Internamente todos los métodos mágicos (e interfaces excepto JsonSerializable) se implementan utilizando manejadores de objetos o técnicas similares: esto permite eludir llamadas a métodos relativamente lentas.
Métodos
final public function __construct( array $data = null );
Constructor
final public function __get( string $element ): mixed;
Getter mágico para obtener un elemento de la colección
final public function __isset( string $element ): bool;
Isset mágico para comprobar si un elemento existe o no
final public function __set( string $element, mixed $value ): void;
Setter mágico para asignar valores a un elemento
final public function __unset( string $element ): void;
Unset mágico para eliminar un elemento de la colección
final public function clear(): void;
Limpia la colección interna
final public function count(): int;
Cuenta los elementos de un objeto
@link https://php.net/manual/en/countable.count.php
final public function get( string $element, mixed $defaultValue = null, string $cast = null ): mixed;
Obtiene el elemento de la colección
final public function getIterator(): Traversable;
Devuelve el iterador de la clase
final public function has( string $element ): bool;
Determina si un elemento está presente en la colección.
final public function init( array $data = [] ): void;
Inicializa el vector interno
final public function jsonSerialize(): array;
Especifica los datos que deben ser serializados a JSON
@link https://php.net/manual/en/jsonserializable.jsonserialize.php
final public function offsetExists( mixed $element ): bool;
Si existe un desplazamiento
@link https://php.net/manual/en/arrayaccess.offsetexists.php
final public function offsetGet( mixed $element ): mixed;
Desplazamiento a obtener
@link https://php.net/manual/en/arrayaccess.offsetget.php
final public function offsetSet( mixed $element, mixed $value ): void;
Desplazamiento a establecer
@link https://php.net/manual/en/arrayaccess.offsetset.php
final public function offsetUnset( mixed $element ): void;
Desplazamiento a deconfigurar
@link https://php.net/manual/en/arrayaccess.offsetunset.php
final public function remove( string $element ): void;
Elimina el elemento de la colección
final public function serialize(): string;
Representación del objeto como cadena de texto
@link https://php.net/manual/en/serializable.serialize.php
final public function set( string $element, mixed $value ): void;
Establece un elemento en la colección
final public function toArray(): array;
Devuelve el objeto en un formato vector
final public function toJson( int $options = int ): string;
Devuelve el objeto en un formato JSON
La cadena predeterminada usa las siguientes opciones para json_encode
JSON_HEX_TAG, JSON_HEX_APOS, JSON_HEX_AMP, JSON_HEX_QUOT, JSON_UNESCAPED_SLASHES
@see https://www.ietf.org/rfc/rfc4627.txt
final public function unserialize( mixed $serialized ): void;
Construye el objeto
@link https://php.net/manual/en/serializable.unserialize.php