Repository navigation
PhpFileConfig
Class PhpFileConfig.
Provides a configuration source backed by a single PHP file returning an array.
This class MUST load the configuration from the specified PHP file.
It SHALL lazily initialize and retrieve configuration data upon invocation.
If configured as persistent, mutations made via set and remove SHALL be persisted back to the file.
- Full name:
\FastForward\Config\PhpFileConfig - 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 PhpFileConfig instance.
public __construct(string $file, bool $persistent = false, array<string,mixed>|\FastForward\Config\ConfigInterface|null $defaultConfig = null): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$file |
string | the path to the PHP configuration file |
$persistent |
bool | whether changes should be saved back to the file |
$defaultConfig |
array<string,mixed>|\FastForward\Config\ConfigInterface|null | optional default configuration when the file does not exist |
Invokes the configuration and returns the configuration data.
public __invoke(): \FastForward\Config\ConfigInterfaceIf the file exists, it MUST return a valid array. If the file does not exist but a default configuration is provided, the default configuration SHALL be used.
Return Value:
a ConfigInterface implementation containing the configuration data
Throws:
if the file is unreadable or does not return an array
Sets configuration data.
public set(array<string,mixed>|\FastForward\Config\ConfigInterface|string $key, mixed $value = null): voidThis method MUST update the configuration data in the file if the persistent flag is set to true.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$key |
array<string,mixed>|\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 or file cannot be written
Removes a configuration key and its associated value.
public remove(string $key): voidThis method MUST update the configuration data in the file if the persistent flag is set to true.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$key |
string | the configuration key to remove |
Throws:
if the file cannot be written
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