LazyLoadConfigTrait
Trait LazyLoadConfigTrait.
Description
Implements lazy-loading behavior for configuration access. This trait MUST be used in classes implementing ConfigInterface to defer configuration instantiation until first usage. It SHALL invoke the implementing class as a callable to obtain the actual config instance.
Properties
Methods
Implementing class MUST define the __invoke() method to return a ConfigInterface instance.
Retrieves a configuration value by key.
Retrieves an iterator for traversing the configuration data.
Checks for existence of a configuration key.
Removes a configuration key.
Sets configuration data.
Exports the entire configuration to an array.
Retrieves or initializes the configuration instance.
private
ConfigInterface|null
$config
=
null
Description
holds the loaded configuration instance
Implementing class MUST define the __invoke() method to return a ConfigInterface instance.
public
abstract
__invoke() : ConfigInterface
Return values
Description
the actual configuration instance
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
Retrieves an iterator for traversing the configuration data.
public
getIterator() : Traversable
Return values
Description
an iterator over the configuration
Checks for existence of a configuration key.
public
has(
string
$key) : bool
Parameters
$key
:
string
Description
the configuration key to check
Return values
Description
TRUE if the key exists, FALSE otherwise
Removes a configuration key.
public
remove(
string
$key) : void
Parameters
$key
:
string
Description
the configuration key to remove
Sets configuration data.
public
set(
array<string|int, mixed>|ConfigInterface|string
$key[,
mixed|null
$value = null]) : void
Parameters
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
Exports the entire configuration to an array.
public
toArray() : array<string|int, mixed>
Return values
Description
the configuration as an associative array
Retrieves or initializes the configuration instance.
private
getConfig() : ConfigInterface
Return values
Description
the lazily-loaded configuration object