ContainerBuilder
Registers ordered initializers and builds independent container compositions.
Description
Registration SHALL retain source objects and class names without resolving services. Each build() MUST create a fresh aggregate, provider/config adapters, and autowiring container. Supplied PSR-11 containers SHALL be reused without cloning their state.
Later registrations SHALL affect subsequent builds only. Provider adapters SHALL receive their build's aggregate so dependencies can resolve across all sources.
Properties
Methods
Registers one or more initializers for subsequent builds.
Creates a fresh container stack from the registered initializers.
Selects a container implementation for a constructed initializer.
Appends additional initializers declared in a configuration container.
Resolves an initializer object or constructs its class before adaptation.
Registers one or more initializers for subsequent builds.
public
add(ConfigInterface|ContainerInterface|ServiceProviderInterface|string
...$initializers) : self
Description
This method SHALL append sources in their supplied order and return this builder. Class names SHALL be instantiated and adapted when build() is called. Previously built containers MUST NOT be changed by later registrations.
Parameters
$initializers
:
ConfigInterface|ContainerInterface|ServiceProviderInterface|string
Description
the configuration objects, containers, providers, or initializer class names
Return values
Description
this builder for incremental, fluent registration
Creates a fresh container stack from the registered initializers.
public
build() : ContainerInterface
Description
This method SHALL adapt sources in registration order, append optional configured sources, and return an AutowireContainer wrapping the completed aggregate. Class names MUST be instantiable without required constructor arguments. The builder SHALL retain registrations without retaining assembled container state.
Return values
Description
the composed and autowire-enabled container
Selects a container implementation for a constructed initializer.
private
adaptInitializer(
object
$initializer, AggregateContainer
$aggregateContainer) : ContainerInterface
Description
PSR-11 containers SHALL take precedence over provider and configuration adapters. Unsupported objects MUST cause an InvalidArgumentException before reaching the aggregate.
Parameters
$initializer
:
object
Description
the constructed initializer
Description
the shared resolution wrapper
Return values
Description
the container or provider/config adapter
Appends additional initializers declared in a configuration container.
private
appendConfiguredContainers(ConfigContainer
$configContainer, AggregateContainer
$aggregateContainer) : void
Description
Entries SHALL be adapted in order using the existing container configuration key. Failures while reading or adapting this optional configuration SHALL stop that expansion and be ignored, preserving previously appended and later explicit sources.
Parameters
$configContainer
:
ConfigContainer
Description
the configuration entry source
Description
the shared resolution wrapper
Resolves an initializer object or constructs its class before adaptation.
private
resolveInitializer(
mixed
$initializer, AggregateContainer
$aggregateContainer) : ContainerInterface
Description
Existing objects SHALL be passed directly to adapter selection. Class names SHALL be instantiated with an argument-free constructor for each build.
Parameters
$initializer
:
mixed
Description
an initializer object or instantiable class name
Description
the shared resolution wrapper
Return values
Description
the adapted initializer