ConfigHelper
Class ConfigHelper.
Description
Provides a set of static helper methods for manipulating configuration arrays, particularly handling associative arrays with dot notation and nested structures. This class SHALL NOT be instantiated and MUST be used statically.
Methods
Flattens a nested configuration array into a dot-notated traversable set.
Determines if the provided value is an associative array.
Normalizes a configuration array using dot notation delimiters.
This constructor is private to prevent instantiation of the class.
Flattens a nested configuration array into a dot-notated traversable set.
public
static
flatten(
array<string|int, mixed>
$config[,
string
$rootKey = '']) : Traversable<string, mixed>
Description
This method SHALL recursively iterate through the nested array structure and convert it into a flat representation where keys reflect the nested path. A value like ['database' => ['host' => 'localhost']] SHALL be transformed into ['database.host' => 'localhost'].
Parameters
$config
:
array<string|int, mixed>
Description
the configuration array to flatten
$rootKey
:
string
=
''
Description
(Optional) The root key prefix for recursive calls
Return values
Description
a traversable list of flattened key-value pairs
Determines if the provided value is an associative array.
public
static
isAssoc(
mixed
$value) : bool
Description
This method SHALL check whether the given array uses string keys, distinguishing it from indexed arrays.
Parameters
$value
:
mixed
Description
the value to check
Return values
Description
true if the array is associative; false otherwise
Normalizes a configuration array using dot notation delimiters.
public
static
normalize(
array<string|int, mixed>
$config) : array<string|int, mixed>
Description
This method SHALL recursively convert keys containing delimiters into nested arrays. For example, a key like "database.host" SHALL be transformed into ['database' => ['host' => 'value']].
Parameters
$config
:
array<string|int, mixed>
Description
the configuration array to normalize
Return values
Description
the normalized configuration array
This constructor is private to prevent instantiation of the class.
private
__construct() : mixed
Description
The class MUST be used in a static context only.