-
-
Notifications
You must be signed in to change notification settings - Fork 0
CachedConfig
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
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 | the cache key to use for storing the configuration data |
Invokes the configuration and returns the cached configuration data.
public __invoke(): \FastForward\Config\ConfigInterfaceIf 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
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
Retrieves a configuration value by key.
public remove(string $key): mixedThis 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
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