ConfigHelper

Class
Final: Yes

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.

Table of Contents

Methods

flatten()

Flattens a nested configuration array into a dot-notated traversable set.

 : Traversable<string, mixed>
isAssoc()

Determines if the provided value is an associative array.

 : bool
normalize()

Normalizes a configuration array using dot notation delimiters.

 : array<string|int, mixed>
__construct()

This constructor is private to prevent instantiation of the class.

 : mixed
Methods

flatten()

Public Static

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
Traversable<string, mixed>

Description

a traversable list of flattened key-value pairs

isAssoc()

Public Static

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
bool

Description

true if the array is associative; false otherwise

normalize()

Public Static

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
array<string|int, mixed>

Description

the normalized configuration array

__construct()

Private

This constructor is private to prevent instantiation of the class.

private __construct() : mixed

Description

The class MUST be used in a static context only.