A factory that wraps a user-provided callable and executes it when invoked.
Description
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.
Interfaces
Defines a contract for service factories that rely on a PSR-11 container for instantiation.
Properties
Methods
Constructs a CallableFactory instance.
Invokes the factory to create a service.
Retrieves the arguments for the callable from the container.
Constructs a CallableFactory instance.
public
__construct(
callable
$callable) : mixed
Parameters
$callable
:
callable
Description
a callable that returns a service instance and accepts a container
Invokes the factory to create a service.
public
__invoke(ContainerInterface
$container) : mixed
Parameters
$container
:
ContainerInterface
Description
the PSR-11 container for dependency resolution
Return values
Description
the constructed service instance
Retrieves the arguments for the callable from the container.
private
getArguments(ContainerInterface
$container, ReflectionFunction
$function) : array<string|int, mixed>
Parameters
$container
:
ContainerInterface
Description
the PSR-11 container for dependency resolution
$function
:
ReflectionFunction
Description
the reflection function of the callable
Return values
Description
the resolved arguments for the callable