Class CachedConfig.
Description
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.
Interfaces
Properties
Methods
Constructs a CachedConfig wrapper.
Invokes the configuration and returns the cached configuration data.
Retrieves a configuration value by key.
Retrieves an iterator for traversing the configuration data.
Checks for existence of a configuration key.
Retrieves a configuration value by key.
Sets configuration data.
Exports the entire configuration to an array.
Retrieves or initializes the configuration instance.
private
CacheInterface
$cache
private
string|null
$cacheKey
=
null
private
ConfigInterface|null
$config
=
null
Description
holds the loaded configuration instance
private
ConfigInterface
$defaultConfig
private
bool
$persistent
=
false
Constructs a CachedConfig wrapper.
public
__construct(CacheInterface
$cache, ConfigInterface
$defaultConfig[,
bool
$persistent = false][,
string|null
$cacheKey = null]) : mixed
Description
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
$cache
:
CacheInterface
Description
the cache implementation used for storing configuration data
Description
the configuration source to be cached
$persistent
:
bool
=
false
Description
whether the cache should be persistent or not
$cacheKey
:
string|null
=
null
Description
the cache key to use for storing the configuration data
Invokes the configuration and returns the cached configuration data.
public
__invoke() : ConfigInterface
Description
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.
Description
if the cache key is invalid
Return values
Description
a ConfigInterface implementation containing the cached configuration data
Retrieves a configuration value by key.
public
get(
string
$key[,
mixed|null
$default = null]) : mixed
Parameters
$key
:
string
Description
the configuration key to retrieve
$default
:
mixed|null
=
null
Description
the default value if the key is not found
Return values
Description
the value of the configuration key or the default
Retrieves an iterator for traversing the configuration data.
public
getIterator() : Traversable
Return values
Description
an iterator over the configuration
Checks for existence of a configuration key.
public
has(
string
$key) : bool
Parameters
$key
:
string
Description
the configuration key to check
Return values
Description
TRUE if the key exists, FALSE otherwise
Retrieves a configuration value by key.
public
remove(
string
$key) : mixed
Description
This method MUST return the cached value if it exists, or the default value if not found.
Parameters
$key
:
string
Description
the configuration key to retrieve
Return values
Description
the configuration value or the default value
Sets configuration data.
public
set(
array<string|int, mixed>|ConfigInterface|string
$key[,
mixed
$value = null]) : void
Description
This method MUST update the cached configuration data in the cache if the persistent flag is set to true.
Parameters
Description
the configuration key or an array of key-value pairs to set
$value
:
mixed
=
null
Description
the value to set for the specified key
Description
if the key is invalid
Exports the entire configuration to an array.
public
toArray() : array<string|int, mixed>
Return values
Description
the configuration as an associative array
Retrieves or initializes the configuration instance.
private
getConfig() : ConfigInterface
Return values
Description
the lazily-loaded configuration object