AggregateContainer

Class
implements ContainerInterface

Aggregates multiple PSR-11 containers and delegates resolution requests among them.

Description

This container implementation respects PSR-11 expectations and throws a NotFoundException when a requested service cannot be found in any delegated container.

It caches resolved entries to prevent redundant calls to delegated containers.

Table of Contents

Interfaces

ContainerInterface

Extends the PSR-11 ContainerInterface to provide a consistent, domain-specific container interface for the FastForward ecosystem.

Constants

 = 'container'

Properties

 : array<string|int, ContainerInterface>
 : array<string, mixed>

Methods

__construct()

Constructs the AggregateContainer with one or more delegated containers.

 : mixed
append()

Appends a container to the end of the aggregated list.

 : void
get()

Retrieves the entry associated with the given identifier.

 : mixed
has()

Determines whether a service identifier can be resolved.

 : bool
prepend()

Prepends a container to the beginning of the aggregated list.

 : void
isResolvedByContainer()

Determines whether the identifier has already been resolved by this container.

 : bool
Constants

Constants

ALIAS

Public
public string ALIAS = 'container'

Description

container alias for reference binding

Properties

$resolved

Private
private array<string, mixed> $resolved = []

Description

a registry of already resolved service identifiers

Methods

__construct()

Public

Constructs the AggregateContainer with one or more delegated containers.

public __construct(ContainerInterface  ...$containers) : mixed

Description

The constructor SHALL bind itself to common aliases, including the class name and the PSR-11 interface, to simplify resolution of the container itself.

Parameters
$containers : ContainerInterface

Description

One or more container implementations to aggregate.

append()

Public

Appends a container to the end of the aggregated list.

public append(ContainerInterface  $container) : void

Description

This method MAY be used to dynamically expand the resolution pool.

Parameters
$container : ContainerInterface

Description

the container to append

get()

Public

Retrieves the entry associated with the given identifier.

public get( string  $id) : mixed

Description

This method SHALL resolve from its internal cache first, and otherwise iterate through the aggregated containers to resolve the entry. It MUST throw a NotFoundException if the identifier cannot be resolved.

Parameters
$id : string

Description

the identifier of the entry to retrieve

Tags
throws

Description

if the identifier cannot be found in any aggregated container

throws
ContainerExceptionInterface

Description

if the container cannot resolve the entry

Return values

Description

the resolved entry

has()

Public

Determines whether a service identifier can be resolved.

public has( string  $id) : bool

Description

This method SHALL return true if the identifier is pre-resolved or can be located in any of the aggregated containers.

Parameters
$id : string

Description

the identifier of the entry to look for

Return values
bool

Description

true if the entry exists, false otherwise

prepend()

Public

Prepends a container to the beginning of the aggregated list.

public prepend(ContainerInterface  $container) : void

Description

This method MAY be used to prioritize a container during resolution.

Parameters
$container : ContainerInterface

Description

the container to prepend

isResolvedByContainer()

Private

Determines whether the identifier has already been resolved by this container.

private isResolvedByContainer( string  $id) : bool

Description

This method is used internally to avoid unnecessary delegation to sub-containers.

Parameters
$id : string

Description

the identifier to check

Return values
bool

Description

true if the identifier is already resolved, false otherwise