Repository navigation
ServiceProviderContainer
Implements a PSR-11 compliant dependency injection container using a container-interop/service-provider.
This container SHALL resolve services by delegating to the factories and extensions defined in the provided ServiceProviderInterface instance.
Services are lazily instantiated on first request and cached for subsequent retrieval, enforcing singleton-like behavior within the container scope.
The container supports service extension mechanisms by allowing callable extensions to modify or enhance services after construction, based on the service identifier or its concrete class name.
If an optional wrapper container is provided, it SHALL be passed to service factories and extensions, allowing for delegation or decoration of service resolution. If omitted, the container defaults to itself.
- Full name:
\FastForward\Container\ServiceProviderContainer - This class is marked as final and can't be subclassed
- This class implements:
\FastForward\Container\ContainerInterface - This class is a Final class
Constructs a new ServiceProviderContainer instance.
public __construct(\Interop\Container\ServiceProviderInterface $serviceProvider, \Psr\Container\ContainerInterface|null $wrapperContainer = null): mixedThis constructor SHALL initialize the container with a service provider and an optional delegating container. If no wrapper container is provided, the container SHALL delegate to itself.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$serviceProvider |
\Interop\Container\ServiceProviderInterface | the service provider supplying factories and extensions |
$wrapperContainer |
\Psr\Container\ContainerInterface|null | An optional container for delegation. Defaults to self. |
Determines if the container can return an entry for the given identifier.
public has(string $id): boolThis method MUST return true for cached entries, callable factories, or callable ID-based extensions. It SHALL NOT execute factories or extensions to discover an entry.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$id |
string | identifier of the entry to look for |
Return Value:
true if the entry exists, false otherwise
Throws:
if provider metadata cannot be read
Retrieves a service from the container by its identifier.
public get(string $id): mixedThis method SHALL return a cached instance if available, otherwise it resolves the service using the factory provided by the service provider.
Extensions SHALL receive the previous value and may replace it. Without a factory, an ID-based extension receives null. The final value SHALL be cached, including null.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$id |
string | the identifier of the service to retrieve |
Return Value:
the service instance associated with the identifier
Throws:
if neither a callable factory nor an ID-based extension exists
-
NotFoundExceptionif factory or extension resolution fails or a dependency cycle exists ContainerException