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.
Interfaces
Extends the PSR-11 ContainerInterface to provide a consistent, domain-specific container interface for the FastForward ecosystem.
Constants
Properties
Methods
Constructs the AggregateContainer with one or more delegated containers.
Appends a container to the end of the aggregated list.
Retrieves the entry associated with the given identifier.
Determines whether a service identifier can be resolved.
Prepends a container to the beginning of the aggregated list.
Determines whether the identifier has already been resolved by this container.
private
array<string|int, ContainerInterface>
$containers
=
[]
Description
the array of containers aggregated by this instance
private
array<string, mixed>
$resolved
=
[]
Description
a registry of already resolved service identifiers
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.
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
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
Description
if the container cannot resolve the entry
Return values
Description
the resolved entry
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
Description
true if the entry exists, false otherwise
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
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
Description
true if the identifier is already resolved, false otherwise