Skip to content

CachedConfig

github-actions edited this page Mar 27, 2026 · 1 revision

Class CachedConfig.

Provides a cached implementation of a configuration source. This class MUST cache the configuration output of the decorated ConfigInterface instance. It SHALL lazily initialize and retrieve cached configuration data upon invocation.


  • Full name: \FastForward\Config\CachedConfig
  • This class is marked as final and can't be subclassed
  • This class implements: \FastForward\Config\ConfigInterface
  • This class is a Final class

Methods

__construct

Constructs a CachedConfig wrapper.

public __construct(\Psr\SimpleCache\CacheInterface $cache, \FastForward\Config\ConfigInterface $defaultConfig, bool $persistent = false, string|null $cacheKey = null): mixed

This constructor SHALL accept a PSR-16 cache implementation and a configuration instance to be cached. It MUST defer reading and writing the configuration until invoked.

Parameters:

Parameter Type Description
$cache \Psr\SimpleCache\CacheInterface the cache implementation used for storing configuration data
$defaultConfig \FastForward\Config\ConfigInterface the configuration source to be cached
$persistent bool whether the cache should be persistent or not
$cacheKey string|null the cache key to use for storing the configuration data

__invoke

Invokes the configuration and returns the cached configuration data.

public __invoke(): \FastForward\Config\ConfigInterface

If the configuration has not yet been cached, it MUST be stored in the cache upon first invocation. This method MUST return a ConfigInterface implementation containing the cached configuration data.

Return Value:

a ConfigInterface implementation containing the cached configuration data

Throws:

if the cache key is invalid


set

Sets configuration data.

public set(array|\FastForward\Config\ConfigInterface|string $key, mixed $value = null): void

This method MUST update the cached configuration data in the cache if the persistent flag is set to true.

Parameters:

Parameter Type Description
$key array|\FastForward\Config\ConfigInterface|string the configuration key or an array of key-value pairs to set
$value mixed the value to set for the specified key

Throws:

if the key is invalid


remove

Retrieves a configuration value by key.

public remove(string $key): mixed

This method MUST return the cached value if it exists, or the default value if not found.

Parameters:

Parameter Type Description
$key string the configuration key to retrieve

Return Value:

the configuration value or the default value


Inherited methods

__invoke

Implementing class MUST define the __invoke() method to return a ConfigInterface instance.

public __invoke(): \FastForward\Config\ConfigInterface
  • This method is abstract. Return Value:

the actual configuration instance


get

Retrieves a configuration value by key.

public get(string $key, mixed|null $default = null): mixed

Parameters:

Parameter Type Description
$key string the configuration key to retrieve
$default mixed|null the default value if the key is not found

Return Value:

the value of the configuration key or the default


has

Checks for existence of a configuration key.

public has(string $key): bool

Parameters:

Parameter Type Description
$key string the configuration key to check

Return Value:

TRUE if the key exists, FALSE otherwise


set

Sets configuration data.

public set(array|\FastForward\Config\ConfigInterface|string $key, mixed|null $value = null): void

Parameters:

Parameter Type Description
$key array|\FastForward\Config\ConfigInterface|string the key or set of keys/values to set
$value mixed|null the value to set if a single key is provided

remove

Removes a configuration key.

public remove(string $key): void

Parameters:

Parameter Type Description
$key string the configuration key to remove

toArray

Exports the entire configuration to an array.

public toArray(): array

Return Value:

the configuration as an associative array


getIterator

Retrieves an iterator for traversing the configuration data.

public getIterator(): \Traversable

Return Value:

an iterator over the configuration


Clone this wiki locally