public function __invoke(Configurator $configurator, $container) { $configurator->add("vanillaPerson", Person::class, ["myname", 100, "Earth", null], "prototype", true); $configurator->add("personInjectAll", Person::class, [new Inject(), new Inject(), new Inject(), new Inject()], "prototype", true); $configurator->add("personFirstThreeArgumentsInjected", Person::class, [new Inject(), new Inject(), new Inject(), new Reference("vanillaPerson")], "prototype", true); $configurator->add("child", Person::class, ["myname", 25, "Earth", new Reference("mother")], "prototype", true); $configurator->add("mother", Person::class, ["myname", 50, "Earth", new Reference("vanillaPerson")]); $configurator->add("factoryBuilderTest", self::class); $configurator->add("personBuilder", Person::class)->setFactoryService("factoryBuilderTest")->setFactoryMethod("createPerson"); $configurator->addFactory("personFactory", "personBuilder"); $configurator->add("factoryBuilderTest", self::class)->setProperties(["container" => new Reference("service_container"), "vanillaPersonFactory" => new Reference("vanillaPersonFactory"), "personInjectAllFactory" => new Reference("personInjectAllFactory"), "personFirstThreeArgumentsInjectedFactory" => new Reference("personFirstThreeArgumentsInjectedFactory"), "childFactory" => new Reference("childFactory"), "personFactory" => new Reference("personFactory")]); }
public function getContainer() { $container = new ContainerBuilder(); $configurator = new Configurator($container); // check we've got some resources delcared if (!($resources = $this->getResources())) { // is the class itself a resource? if ($this->reflector->hasMethod('__invoke')) { $resources[] = $reflector->getName(); } throw new NoResourcesDefinedException($reflector); } $configurator->load($resources); $container->compile(); return $container; }