ConfigInterface

Interface
extends IteratorAggregate ArrayAccess

Interface ConfigInterface.

Description

Defines the contract for configuration storage and access. Implementing classes MUST support key-based configuration retrieval, nested data export, and mutation in a standardized format.

This interface SHALL extend the IteratorAggregate interface to allow iteration.

Keys MAY use dot notation to access nested structures, e.g., my.next.key corresponds to ['my' => ['next' => ['key' => $value]]].

Table of Contents

Methods

get()

Retrieves a value from the configuration by key.

 : mixed
has()

Determines if the specified key exists in the configuration.

 : bool
remove()

Removes a configuration key and its associated value.

 : void
set()

Sets a configuration value or merges an array or ConfigInterface.

 : void
toArray()

Exports the configuration as a nested associative array.

 : array<string|int, mixed>
Methods

get()

Public

Retrieves a value from the configuration by key.

public get( string  $key[, mixed  $default = null]) : mixed

Description

Dot notation MAY be used to access nested keys. If the key does not exist, the provided default value MUST be returned. Implementations MAY return complex nested structures or objects.

Parameters
$key : string

Description

the configuration key to retrieve

$default : mixed = null

Description

the default value if the key is not present

Return values

Description

the value associated with the key or the default

has()

Public

Determines if the specified key exists in the configuration.

public has( string  $key) : bool

Description

Dot notation MAY be used to check nested keys.

Parameters
$key : string

Description

the 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

Dot notation MAY be used to specify nested keys. If the key does not exist, this method MUST do nothing.

Parameters
$key : string

Description

the configuration key to remove

set()

Public

Sets a configuration value or merges an array or ConfigInterface.

public set( array<string|int, mixed>|self|string  $key[, mixed|null  $value = null]) : void

Description

Dot notation MAY be used to set values into nested structures. The method MUST support:

  • Setting a single key/value pair.
  • Merging an entire associative array.
  • Merging another ConfigInterface instance.
Parameters
$key : array<string|int, mixed>|self|string

Description

a configuration key, an array, or another ConfigInterface

$value : mixed|null = null

Description

the value to assign, if a key is provided

toArray()

Public

Exports the configuration as a nested associative array.

public toArray() : array<string|int, mixed>

Description

Implementations MUST return a deep array representation of all configuration data.

Return values
array<string|int, mixed>

Description

the full configuration array