Skip to documentation

ContainerBuilder

Class
Final: Yes

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.

Table of Contents

Properties

 : array<int, ConfigInterface|ContainerInterface|ServiceProviderInterface|string>

Methods

add()

Registers one or more initializers for subsequent builds.

 : self
build()

Creates a fresh container stack from the registered initializers.

 : ContainerInterface
adaptInitializer()

Selects a container implementation for a constructed initializer.

 : ContainerInterface
appendConfiguredContainers()

Appends additional initializers declared in a configuration container.

 : void
resolveInitializer()

Resolves an initializer object or constructs its class before adaptation.

 : ContainerInterface
Properties

$initializers

Private
private array<int, ConfigInterface|ContainerInterface|ServiceProviderInterface|string> $initializers = []

Description

the ordered sources retained for subsequent builds

Methods

add()

Public

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
self

Description

this builder for incremental, fluent registration

build()

Public

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.

Tags
throws

Description

if an initializer class cannot be found or adapted

Return values

Description

the composed and autowire-enabled container

adaptInitializer()

Private

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

$aggregateContainer : AggregateContainer

Description

the shared resolution wrapper

Tags
throws

Description

if the initializer object cannot be adapted

Return values
ContainerInterface

Description

the container or provider/config adapter

appendConfiguredContainers()

Private

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

$aggregateContainer : AggregateContainer

Description

the shared resolution wrapper

resolveInitializer()

Private

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

$aggregateContainer : AggregateContainer

Description

the shared resolution wrapper

Tags
throws

Description

if an initializer class cannot be found or adapted

Return values
ContainerInterface

Description

the adapted initializer

Search results