A factory that resolves an alias to another service within a PSR-11 container.
Description
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.
Interfaces
Defines a contract for service factories that rely on a PSR-11 container for instantiation.
Properties
Methods
Constructs the AliasFactory with the target service identifier.
Resolves the aliased service from the container.
Retrieves or creates a cached AliasFactory for a given alias.
Constructs the AliasFactory with the target service identifier.
public
__construct(
string
$alias) : mixed
Parameters
$alias
:
string
Description
the identifier of the service to which this factory points
Resolves the aliased service from the container.
public
__invoke(ContainerInterface
$container) : mixed
Description
This method MUST return the same instance as if the original alias identifier were used directly with the container.
Parameters
$container
:
ContainerInterface
Description
the container instance to resolve the alias from
Return values
Description
the resolved service instance
Retrieves or creates a cached AliasFactory for a given alias.
public
static
get(
string
$alias) : self
Description
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
Description
the identifier to create or retrieve the factory for
Return values
Description
an AliasFactory instance associated with the provided alias