ServiceFactory

Class
implements FactoryInterface
Read only: Yes Final: Yes

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

Description

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.

Table of Contents

Interfaces

FactoryInterface

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

Properties

 : mixed

Methods

__construct()

Constructs the factory with a fixed service instance.

 : mixed
__invoke()

Returns the fixed service instance.

 : mixed
Properties
Methods

__construct()

Public

Constructs the factory with a fixed service instance.

public __construct( mixed  $service) : mixed
Parameters
$service : mixed

Description

the service instance to be returned by the factory

__invoke()

Public

Returns the fixed service instance.

public __invoke(ContainerInterface  $container) : mixed
Parameters
$container : ContainerInterface

Description

the container instance (ignored in this context)

Return values

Description

the predefined service instance