Skip to content

ServiceFactory

github-actions edited this page Mar 27, 2026 · 3 revisions

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


Clone this wiki locally