Skip to content

PhpFileConfig

github-actions[bot] edited this page Oct 9, 2026 · 1 revision

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

Methods

__construct

Constructs a PhpFileConfig instance.

public __construct(string $file, bool $persistent = false, array<string,mixed>|\FastForward\Config\ConfigInterface|null $defaultConfig = null): mixed

Parameters:

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

__invoke

Invokes the configuration and returns the configuration data.

public __invoke(): \FastForward\Config\ConfigInterface

If 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


set

Sets configuration data.

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

This 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


remove

Removes a configuration key and its associated value.

public remove(string $key): void

This 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


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