A registry is a container for storing objects and values in the Flextype application space. By storing the value in a registry, the same object is always available throughout Flextype application. This mechanism is an alternative to using global storage. Flextype Registry is build on top of Atomastic Registry Component.

Methods

Name Description
getInstance Gets the instance via lazy initialization (created on first usage)
get Get item from the registry.
set Set an registry data to a given value using "dot" notation. If no key is given to the method, the entire registry data will be replaced.
has Determine if the registry has a value for the given name.
all Get all items from the registry.
delete Get item from the registry.
flush Flush all items from the registry.

Methods Details

getInstance

Gets the instance via lazy initialization (created on first usage)

/**
 * Gets the instance via lazy initialization (created on first usage)
 */
public static function getInstance(): Registry

Examples

Get flextype.settings.timezone item from the registry.

$flextype_timezone = flextype('registry')->get('flextype.settings.timezone');
get

Get item from the registry.

/**
 * Get item from the registry.
 *
 * @param  string $key     The name of the item to fetch.
 * @param  mixed  $default Default value
 */
public function get(string $key, $default = null)

Examples

Get flextype.settings.timezone item from the registry.

$flextype_timezone = flextype('registry')->get('flextype.settings.timezone');
set

Set an registry data to a given value using "dot" notation. If no key is given to the method, the entire registry data will be replaced.

/**
 * Set an registry data to a given value using "dot" notation.
 *
 * If no key is given to the method, the entire registry data will be replaced.
 *
 * @param  string $key   Key
 * @param  mixed  $value Value
 */
public function set(string $key, $value): self

Examples

Set flextype.settings.timezone item in the registry.

flextype('registry')->set('flextype.settings.timezone', 'America/New_York');
has

Determine if the registry has a value for the given name.

/**
 * Determine if the registry has a value for the given name.
 *
 * @param  string|array $keys The keys of the registry item to check for existence.
 */
public function has($keys): bool

Examples

Checks if an flextype.settings.timezone item with this key name is in the registry.

if (flextype('registry')->has('flextype.settings.timezone')) {
    // do something...
}
all

Get all items from the registry.

/**
 * Get all items from the registry.
 */
public function all(): array

Examples

$registry = flextype('registry')->all();
delete()

Delete a items from the registry.

/**
 * Delete a items from the registry.
 *
 * @param  array|string $keys Keys
 */
public function delete($keys): self

Examples

flextype('registry')->delete('flextype.settings.timezone');
flush

Flush all values from the registry.

/**
 * Flush all items from the registry.
 */
public function flush(): void

Examples

flextype('registry')->flush();

On This Page