ConfigContainer

Class
implements ContainerInterface
Read only: Yes Final: Yes

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.

Table of Contents

Interfaces

Constants

 = 'config'

Properties

Methods

__construct()

Constructs a new ConfigContainer instance.

 : mixed
get()

Retrieves an entry of the container by its identifier.

 : mixed
has()

Determines whether the container can return an entry for the given identifier.

 : bool
isResolvedByContainer()

Determines whether the given identifier is resolved internally by the container itself.

 : bool
Constants

Constants

ALIAS

Public
public string ALIAS = 'config'

Description

the standard identifier for retrieving the configuration object

Properties
Methods

__construct()

Public

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
$config : ConfigInterface

Description

the configuration instance to expose as a container

get()

Public

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

Tags
throws

Description

if the identifier cannot be resolved

Return values

Description

the value associated with the identifier

has()

Public

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
bool

Description

true if the entry can be resolved; false otherwise

isResolvedByContainer()

Private

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
bool

Description

true if the identifier is resolved internally; false otherwise