Skip to content

CallableFactory

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

CallableFactory

A factory that wraps a user-provided callable and executes it when invoked.

The callable MUST accept a PSR-11 ContainerInterface as its first and only argument. This factory SHALL be used when the construction logic must be fully delegated to a closure.

This class allows dynamic resolution of services using the container context.

Methods

__construct

Constructs a CallableFactory instance.

public __construct(callable $callable): mixed

Parameters:

Parameter Type Description
$callable callable a callable that returns a service instance and accepts a container

__invoke

Invokes the factory to create a service.

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

Parameters:

Parameter Type Description
$container \Psr\Container\ContainerInterface the PSR-11 container for dependency resolution

Return Value:

the constructed service instance



Automatically generated on 2025-07-03

Clone this wiki locally