Gets the factory.
public getFactory ( ) : string | array | ||
return | string | array | The PHP function or an array containing a class/Reference and a method to call |
use Symfony\Component\DependencyInjection\Definition; // Define a service definition that creates a new instance of a custom factory class $factoryDefinition = new Definition('My\Custom\Factory'); $factoryDefinition->addMethodCall('setConfig', ['someconfig']); // Define a service definition that uses the factory to create its instance object $serviceDefinition = new Definition('My\Custom\Service'); $serviceDefinition->setFactory([$factoryDefinition, 'create']); $serviceDefinition->addArgument('somearg'); // Retrieve the factory service definition from the service definition $factoryServiceDefinition = $serviceDefinition->getFactory(); // Get the class name of the factory service definition $factoryClassName = $factoryServiceDefinition->getClass(); // Get the arguments that were passed to the factory service definition constructor $factoryConstructorArgs = $factoryServiceDefinition->getArguments();
use Symfony\Component\DependencyInjection\ContainerBuilder; // Create a new container builder $containerBuilder = new ContainerBuilder(); // Define a service definition that creates a new instance of a custom factory class $containerBuilder->register('my_factory', 'My\Custom\Factory') ->addMethodCall('setConfig', ['someconfig']); // Define a service definition that uses the factory to create its instance object $containerBuilder->register('my_service', 'My\Custom\Service') ->setFactory(['my_factory', 'create']) ->addArgument('somearg'); // Retrieve the factory service definition from the service definition $factoryServiceDefinition = $containerBuilder->getDefinition('my_service')->getFactory(); // Get the class name of the factory service definition $factoryClassName = $factoryServiceDefinition->getClass(); // Get the arguments that were passed to the factory service definition constructor $factoryConstructorArgs = $factoryServiceDefinition->getArguments();In this example, we use the Symfony container builder to define the custom factory class and service. We then retrieve the factory service definition from the service definition and get information about it, such as its class name and constructor arguments. Package library: Symfony\Component\DependencyInjection
public getFactory ( ) : string | array | ||
return | string | array | The PHP function or an array containing a class/Reference and a method to call |