ConfigContainer
Class ConfigContainer.
Description
Provides a PSR-11 compatible container interface for accessing configuration values.
This container implementation SHALL resolve configuration keys by prefix using the alias "config". For example, a request for "config.db.host" will attempt to fetch the key "db.host" from the underlying ConfigInterface.
Identifiers such as 'config', ConfigInterface::class, and the concrete config class MUST return the configuration instance itself. Requests for unknown or invalid identifiers MUST result in a ContainerNotFoundException.
Interfaces
Constants
Properties
Methods
Constructs a new ConfigContainer instance.
Retrieves an entry of the container by its identifier.
Determines whether the container can return an entry for the given identifier.
Determines whether the given identifier is resolved internally by the container itself.
private
ConfigInterface
$config
Constructs a new ConfigContainer instance.
public
__construct(ConfigInterface
$config) : mixed
Description
This constructor SHALL wrap an existing ConfigInterface instance and expose it
through PSR-11 get() and has() methods with namespace-style key resolution.
Parameters
Description
the configuration instance to expose as a container
Retrieves an entry of the container by its identifier.
public
get(
string
$id) : mixed
Description
This method SHALL resolve identifiers in the following order:
- If the identifier matches 'config', ConfigInterface::class, or the concrete config class, it SHALL return the ConfigInterface instance itself.
- If the identifier is prefixed with 'config.', the suffix SHALL be used to query the configuration. If the configuration key exists, its value SHALL be returned.
- If the identifier cannot be resolved, a ContainerNotFoundException MUST be thrown.
Parameters
$id
:
string
Description
identifier of the entry to retrieve
Return values
Description
the value associated with the identifier
Determines whether the container can return an entry for the given identifier.
public
has(
string
$id) : bool
Description
This method SHALL return true if:
- The identifier matches known internal bindings (alias, interface, or class).
- The identifier is prefixed with 'config' and corresponds to an existing key in the configuration.
Parameters
$id
:
string
Description
identifier of the entry to look for
Return values
Description
true if the entry can be resolved; false otherwise
Determines whether the given identifier is resolved internally by the container itself.
private
isResolvedByContainer(
string
$id) : bool
Description
This method SHALL match the identifier against:
- the alias "config"
- the ConfigInterface::class string
- the concrete class of the injected configuration instance
Parameters
$id
:
string
Description
the identifier to check
Return values
Description
true if the identifier is resolved internally; false otherwise