final class Config (View source)

Mutable runtime configuration store for framework and application settings.

The store supports dot-notation keys, provides both generic and typed access helpers, and allows direct setting and recursive merging of configuration values. The framework.providers branch uses replace-only merge semantics and is not merged by numeric indexes.

Methods

__construct(array $items = [])

Creates a configuration store with optional initial items.

array
all()

Returns the complete current configuration state.

array
mixed
get(string $key, mixed $default = null)

Returns a configuration value resolved through dot notation.

mixed
mixed
require(string $key)

Returns a required configuration value.

mixed
string|null
string(string $key, string|null $default = null)

Returns the resolved configuration value converted to a string when possible.

string|null
string
requiredString(string $key)

Returns a required non-empty string configuration value.

string
int
int(string $key, int $default = 0)

Returns the resolved configuration value as an integer.

int
bool
bool(string $key, bool $default = false)

Returns the resolved configuration value as a boolean.

bool
array
array(string $key, array $default = [])

Returns the resolved configuration value when it is an array.

array
void
set(string $key, mixed $value)

Sets a configuration value through dot notation.

void
void
merge(array $items)

Recursively merges configuration values into the current state.

void

Details

__construct

__construct(array $items = [])

Creates a configuration store with optional initial items.

Parameters

array $items

all

array all()

Returns the complete current configuration state.

Return Value

array

get

mixed get(string $key, mixed $default = null)

Returns a configuration value resolved through dot notation.

When any path segment is missing, the provided default value is returned. If the key exists and its value is explicitly null, null is returned.

Parameters

string $key

Dot-notation configuration key to resolve.

mixed $default

Fallback value returned when the key path does not exist.

Return Value

mixed

require

mixed require(string $key)

Returns a required configuration value.

Values such as false, 0, an empty string, and an empty array are accepted. Only missing or explicit null values are treated as absent.

Parameters

string $key

Return Value

mixed

Exceptions

RuntimeException

string

string|null string(string $key, string|null $default = null)

Returns the resolved configuration value converted to a string when possible.

Scalar values are cast to string. When the resolved value is null or is not scalar, the method returns null. The default value is used when the key path does not exist.

Parameters

string $key
string|null $default

Return Value

string|null

requiredString

string requiredString(string $key)

Returns a required non-empty string configuration value.

Parameters

string $key

Return Value

string

Exceptions

RuntimeException

int

int int(string $key, int $default = 0)

Returns the resolved configuration value as an integer.

Native integers are returned unchanged. Floats and numeric strings are cast to integers. Any other value falls back to the provided default.

Parameters

string $key
int $default

Return Value

int

bool

bool bool(string $key, bool $default = false)

Returns the resolved configuration value as a boolean.

The method uses PHP boolean validation semantics for scalar values and falls back to the provided default for invalid or non-scalar input. Common textual boolean representations such as "true" and "false" are supported.

Parameters

string $key
bool $default

Return Value

bool

array

array array(string $key, array $default = [])

Returns the resolved configuration value when it is an array.

Parameters

string $key
array $default

Return Value

array

set

void set(string $key, mixed $value)

Sets a configuration value through dot notation.

Missing intermediate segments are created as arrays. Existing intermediate non-array values are replaced with arrays before traversal.

Parameters

string $key
mixed $value

Return Value

void

merge

void merge(array $items)

Recursively merges configuration values into the current state.

Incoming values override existing ones through array_replace_recursive. The framework.providers branch is replaced as a whole instead of being merged by indexes.

Parameters

array $items

Return Value

void