Class ArrayConfig.
Description
Provides a configuration management system with dot notation access. This class SHALL encapsulate configuration data using the DotAccessData library. It MUST support nested keys and provide export, iteration, and dynamic update capabilities.
Interfaces
Properties
Methods
Constructs the ArrayConfig instance.
Retrieves a value from the configuration.
Retrieves a traversable set of flattened configuration data.
Determines whether the given configuration key exists.
Removes a configuration key and its associated value.
Sets configuration values into the internal data store.
Converts the entire configuration to an associative array.
Constructs the ArrayConfig instance.
public
__construct([
array<string|int, mixed>
$config = []]) : mixed
Description
This constructor SHALL initialize the internal configuration store using normalized keys.
Parameters
$config
:
array<string|int, mixed>
=
[]
Description
an optional initial configuration array
Retrieves a value from the configuration.
public
get(
string
$key[,
mixed
$default = null]) : mixed|self
Description
If the value is a nested associative array, a new instance of ArrayConfig SHALL be returned. If the key is not found and no default is provided, a MissingPathException SHOULD be thrown.
Parameters
$key
:
string
Description
the configuration key to retrieve
$default
:
mixed
=
null
Description
the default value to return if the key does not exist
Return values
Description
the configuration value, or a nested ArrayConfig instance
Retrieves a traversable set of flattened configuration data.
public
getIterator() : Traversable<string, mixed>
Description
This method SHALL return an iterator where each key represents the nested path in dot notation, and each value is the corresponding value. For example ['database' => ['host' => 'localhost']] becomes ['database.host' => 'localhost'].
Return values
Description
an iterator of flattened key-value pairs
Determines whether the given configuration key exists.
public
has(
string
$key) : bool
Parameters
$key
:
string
Description
the dot-notation configuration key to check
Return values
Description
TRUE if the key exists, FALSE otherwise
Removes a configuration key and its associated value.
public
remove(
string
$key) : void
Description
If the key does not exist, this method SHALL do nothing.
Parameters
$key
:
string
Description
the configuration key to remove
Sets configuration values into the internal data store.
public
set(
array<string|int, mixed>|ConfigInterface|string
$key[,
mixed|null
$value = null]) : void
Description
If a value is provided, the key MUST be a string. If the input is an associative array or another ConfigInterface instance, it SHALL be normalized before insertion.
Parameters
Description
the configuration key(s) or configuration object
$value
:
mixed|null
=
null
Description
the value to assign to the specified key, if applicable
Converts the entire configuration to an associative array.
public
toArray() : array<string|int, mixed>
Description
This method MUST export the configuration in its current state.
Return values
Description
the exported configuration array