AliasFactory
in package
implements
FactoryInterface
A factory that resolves an alias to another service within a PSR-11 container.
This factory MUST be used when a service should act as an alias for another service already registered in the container.
When invoked, it SHALL delegate resolution to the aliased service identifier.
Table of Contents
Interfaces
- FactoryInterface
- Defines a contract for service factories that rely on a PSR-11 container for instantiation.
Methods
- __construct() : mixed
- Constructs the AliasFactory with the target service identifier.
- __invoke() : mixed
- Resolves the aliased service from the container.
- get() : self
- Retrieves or creates a cached AliasFactory for a given alias.
Methods
__construct()
Constructs the AliasFactory with the target service identifier.
public
__construct(string $alias) : mixed
Parameters
- $alias : string
-
the identifier of the service to which this factory points
__invoke()
Resolves the aliased service from the container.
public
__invoke(ContainerInterface $container) : mixed
This method MUST return the same instance as if the original alias identifier were used directly with the container.
Parameters
- $container : ContainerInterface
-
the container instance to resolve the alias from
Return values
mixed —the resolved service instance
get()
Retrieves or creates a cached AliasFactory for a given alias.
public
static get(string $alias) : self
This static method SHOULD be used to avoid instantiating multiple factories for the same alias unnecessarily. The same instance will be reused for each alias.
Parameters
- $alias : string
-
the identifier to create or retrieve the factory for
Return values
self —an AliasFactory instance associated with the provided alias