AliasFactory

Class
implements FactoryInterface
Final: Yes

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.

Table of Contents

Interfaces

FactoryInterface

Defines a contract for service factories that rely on a PSR-11 container for instantiation.

Properties

 : string
 : array<string, self>

Methods

__construct()

Constructs the AliasFactory with the target service identifier.

 : mixed
__invoke()

Resolves the aliased service from the container.

 : mixed
get()

Retrieves or creates a cached AliasFactory for a given alias.

 : self
Properties

$aliases

Private Static
private static array<string, self> $aliases = []

Description

Registry of AliasFactory instances indexed by alias name. This MAY be used to cache and reuse factory instances.

Methods

__construct()

Public

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

__invoke()

Public

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

get()

Public Static

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
self

Description

an AliasFactory instance associated with the provided alias