InvokableFactory
in package
implements
FactoryInterface
Factory responsible for instantiating a class with constructor arguments.
This class MUST be used when a service should be created using a known class name and optionally injected with fixed arguments.
It SHALL invoke the constructor directly using the spread operator and provided arguments. This factory is suitable for services that do not require container-based dependency injection.
Table of Contents
Interfaces
- FactoryInterface
- Defines a contract for service factories that rely on a PSR-11 container for instantiation.
Methods
- __construct() : mixed
- Constructs the InvokableFactory with a target class and optional constructor arguments.
- __invoke() : mixed
- Creates an instance of the class with the provided arguments.
Methods
__construct()
Constructs the InvokableFactory with a target class and optional constructor arguments.
public
__construct(string $class, mixed ...$arguments) : mixed
This constructor MUST receive a valid, instantiable class name. Any variadic arguments provided SHALL be passed to the class constructor during instantiation. If an argument is a string and matches a service ID in the container, it SHALL be resolved from the container.
Parameters
- $class : string
-
the fully qualified class name to be instantiated
- $arguments : mixed
-
A variadic list of constructor arguments.
__invoke()
Creates an instance of the class with the provided arguments.
public
__invoke(ContainerInterface $container) : mixed
Arguments that are strings and match a known service ID in the container SHALL be replaced with the corresponding container-resolved services.
It MUST return a new instance of the class with the resolved arguments. This method SHALL be invoked by the container when the service is requested.
Parameters
- $container : ContainerInterface
-
The PSR-11 compliant container providing dependencies
Tags
Return values
mixed —The created service instance