AggregateConfig

Class
Final: Yes

Class AggregateConfig.

Description

Represents an aggregated configuration loader that combines multiple configuration sources. This class MUST be used to merge multiple configurations into a single, unified configuration structure.

It SHALL lazily load and resolve configuration data only when invoked.

Table of Contents

Interfaces

ConfigInterface

Interface ConfigInterface.

Properties

 : array<string|int, ConfigInterface>

Methods

__construct()

Constructs a new instance by accepting a variadic list of configuration objects.

 : mixed
__invoke()

Invokes the configuration aggregator.

 : ConfigInterface
get()

Retrieves a configuration value by key.

 : mixed
getIterator()

Retrieves an iterator for traversing the configuration data.

 : Traversable
has()

Checks for existence of a configuration key.

 : bool
remove()

Removes a configuration key.

 : void
set()

Sets configuration data.

 : void
toArray()

Exports the entire configuration to an array.

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

Retrieves or initializes the configuration instance.

 : ConfigInterface
Properties

$configs

Private Read-only
private array<string|int, ConfigInterface> $configs

Description

A list of configuration providers to be aggregated. Each configuration MUST implement ConfigInterface.

Methods

__construct()

Public

Constructs a new instance by accepting a variadic list of configuration objects.

public __construct(ConfigInterface  ...$configs) : mixed

Description

These configuration objects MUST implement the ConfigInterface.

Parameters
$configs : ConfigInterface

Description

One or more configuration instances to aggregate.

__invoke()

Public

Invokes the configuration aggregator.

public __invoke() : ConfigInterface

Description

This method SHALL initialize a new ArrayConfig instance and populate it with the values from each provided configuration source. It MUST return a fully merged configuration in the form of a ConfigInterface implementation.

Return values

Description

the resulting merged configuration object

get()

Public

Retrieves a configuration value by key.

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

Description

the configuration key to retrieve

$default : mixed|null = null

Description

the default value if the key is not found

Return values

Description

the value of the configuration key or the default

getIterator()

Public

Retrieves an iterator for traversing the configuration data.

public getIterator() : Traversable
Return values
Traversable

Description

an iterator over the configuration

has()

Public

Checks for existence of a configuration key.

public has( string  $key) : bool
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.

public remove( string  $key) : void
Parameters
$key : string

Description

the configuration key to remove

set()

Public

Sets configuration data.

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

Description

the key or set of keys/values to set

$value : mixed|null = null

Description

the value to set if a single key is provided

toArray()

Public

Exports the entire configuration to an array.

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

Description

the configuration as an associative array