Skip to content

ServiceFactory

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

ServiceFactory

This factory wraps a predefined service instance and returns it directly upon invocation.

It SHALL be used when a fixed service object must be registered in a container using a factory interface.

The returned value MUST be the exact same instance provided at construction.

This ensures immutability and predictable resolution.

Methods

__construct

Constructs the factory with a fixed service instance.

public __construct(mixed $service): mixed

Parameters:

Parameter Type Description
$service mixed the service instance to be returned by the factory

__invoke

Returns the fixed service instance.

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

Parameters:

Parameter Type Description
$container \Psr\Container\ContainerInterface the container instance (ignored in this context)

Return Value:

the predefined service instance



Automatically generated on 2025-07-03

Clone this wiki locally