Repository navigation
CachedConfig
Class CachedConfig.
Provides a cached implementation of a configuration source. This class SHALL attempt to 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
Constructs a CachedConfig wrapper.
public __construct(\Psr\SimpleCache\CacheInterface $cache, \FastForward\Config\ConfigInterface $defaultConfig, bool $persistent = false, string|null $cacheKey = null): mixedThis 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 | a shared cache key, or null for an isolated key whose entries expire after 300 seconds |
Invokes the configuration and returns the cached configuration data.
public __invoke(): \FastForward\Config\ConfigInterfaceA usable cache entry MUST be returned without resolving the source. A miss or unusable entry SHALL resolve the source and attempt to cache it. A failed initial write MUST NOT discard source data. 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
Sets configuration data.
public set(array|\FastForward\Config\ConfigInterface|string $key, mixed $value = null): voidThis 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
-
InvalidArgumentExceptionif a persistent write fails; the local change is retained RuntimeException
Removes a configuration value by key.
public remove(mixed $key): voidThis method MUST update the backend when persistent mode is enabled.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$key |
mixed | the configuration key to remove |
Throws:
if the cache key is invalid
-
InvalidArgumentExceptionif a persistent write fails; the local change is retained RuntimeException
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
Retrieves a configuration value by key.
public get(string $key, mixed|null $default = null): mixedParameters:
| 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
Checks for existence of a configuration key.
public has(string $key): boolParameters:
| Parameter | Type | Description |
|---|---|---|
$key |
string | the configuration key to check |
Return Value:
TRUE if the key exists, FALSE otherwise
Sets configuration data.
public set(array|\FastForward\Config\ConfigInterface|string $key, mixed|null $value = null): voidParameters:
| 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 |
Removes a configuration key.
public remove(string $key): voidParameters:
| Parameter | Type | Description |
|---|---|---|
$key |
string | the configuration key to remove |
Exports the entire configuration to an array.
public toArray(): arrayReturn Value:
the configuration as an associative array
Retrieves an iterator for traversing the configuration data.
public getIterator(): \TraversableReturn Value:
an iterator over the configuration