Skip to content

AliasFactory

Felipe Sayão Lobato Abreu edited this page Jul 3, 2025 · 2 revisions

AliasFactory

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.

Methods

__construct

Constructs the AliasFactory with the target service identifier.

public __construct(string $alias): mixed

Parameters:

Parameter Type Description
$alias string the identifier of the service to which this factory points

__invoke

Resolves the aliased service from the container.

public __invoke(\Psr\Container\ContainerInterface $container): mixed

This method MUST return the same instance as if the original alias identifier were used directly with the container.

Parameters:

Parameter Type Description
$container \Psr\Container\ContainerInterface the container instance to resolve the alias from

Return Value:

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.

  • This method is static.

Parameters:

Parameter Type Description
$alias string the identifier to create or retrieve the factory for

Return Value:

an AliasFactory instance associated with the provided alias



Automatically generated on 2025-07-03

Clone this wiki locally