ArrayConfig

Class
implements ConfigInterface
uses ArrayAccessConfigTrait
Final: Yes

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.

Table of Contents

Interfaces

ConfigInterface

Interface ConfigInterface.

Properties

 : Data

Methods

__construct()

Constructs the ArrayConfig instance.

 : mixed
get()

Retrieves a value from the configuration.

 : mixed|self
getIterator()

Retrieves a traversable set of flattened configuration data.

 : Traversable<string, mixed>
has()

Determines whether the given configuration key exists.

 : bool
remove()

Removes a configuration key and its associated value.

 : void
set()

Sets configuration values into the internal data store.

 : void
toArray()

Converts the entire configuration to an associative array.

 : array<string|int, mixed>
Properties

$data

Private
private Data $data

Description

internal configuration storage instance

Methods

__construct()

Public

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

get()

Public

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
mixed|self

Description

the configuration value, or a nested ArrayConfig instance

getIterator()

Public

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

Description

an iterator of flattened key-value pairs

has()

Public

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
bool

Description

TRUE if the key exists, FALSE otherwise

remove()

Public

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

set()

Public

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
$key : array<string|int, mixed>|ConfigInterface|string

Description

the configuration key(s) or configuration object

$value : mixed|null = null

Description

the value to assign to the specified key, if applicable

Tags
throws

Description

if the key is not a string when a value is provided

toArray()

Public

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

Description

the exported configuration array