diff --git a/src/ContainerBuilder.php b/src/ContainerBuilder.php index e25dd76..a34a700 100644 --- a/src/ContainerBuilder.php +++ b/src/ContainerBuilder.php @@ -30,17 +30,17 @@ public function populateContainer(Container $container, CompiledConfig $compiled $arguments = $this->resolveArray($container, $definition["arguments"] ?? []); if ($isFactoryCreated) { - return call_user_func_array( + $service = call_user_func_array( [ $definition["factoryClass"] ?? $container->offsetGet(mb_substr($definition["factoryService"], 1)), $definition["factoryMethod"] ], $arguments ); + } else { + $service = (new \ReflectionClass($definition["class"]))->newInstanceArgs($arguments); } - $service = (new \ReflectionClass($definition["class"]))->newInstanceArgs($arguments); - foreach ($definition["calls"] ?? [] as $call) { call_user_func_array( [$service, $call["method"]], diff --git a/src/FileConfig.php b/src/FileConfig.php index 0e7049e..17fd836 100644 --- a/src/FileConfig.php +++ b/src/FileConfig.php @@ -21,7 +21,6 @@ class FileConfig "factoryClass" => 1, "factoryMethod" => 1, "factoryService" => 1, - "factoryArguments" => 1, "aliasOf" => 1, "abstract" => 1, "calls" => 1, diff --git a/tests/integration/FactoryClass/ExampleClass.php b/tests/integration/FactoryClass/ExampleClass.php index 61c04b6..b998c42 100644 --- a/tests/integration/FactoryClass/ExampleClass.php +++ b/tests/integration/FactoryClass/ExampleClass.php @@ -8,6 +8,7 @@ class ExampleClass { protected $serviceExample; protected $tagCollection; + protected $customParameter; public function __construct(ServiceExample $serviceExample, iterable $tagCollection) { @@ -24,4 +25,14 @@ public function getTagCollection() { return $this->tagCollection; } + + public function setCustomParameter(string $customParameter) + { + $this->customParameter = $customParameter; + } + + public function getCustomParameter() : ?string + { + return $this->customParameter; + } } \ No newline at end of file diff --git a/tests/integration/FactoryClass/FactoryTest.php b/tests/integration/FactoryClass/FactoryTest.php index ee2a162..0e6fec1 100644 --- a/tests/integration/FactoryClass/FactoryTest.php +++ b/tests/integration/FactoryClass/FactoryTest.php @@ -23,6 +23,7 @@ public function testFactoryService() $exampleClass = $container->offsetGet("example.class"); self::assertInstanceOf(ExampleClass::class, $exampleClass); self::assertInstanceOf(ServiceExample::class, $exampleClass->getServiceExample()); + self::assertSame("custom_value", $exampleClass->getCustomParameter()); foreach ($exampleClass->getTagCollection() as $tag) { self::assertInstanceOf(TestTagInterface::class, $tag); } @@ -41,6 +42,7 @@ public function testFactoryClass() $exampleClass = $container->offsetGet("example.class.2"); self::assertInstanceOf(ExampleClass::class, $exampleClass); self::assertInstanceOf(ServiceExample::class, $exampleClass->getServiceExample()); + self::assertSame("custom_value", $exampleClass->getCustomParameter()); foreach ($exampleClass->getTagCollection() as $tag) { self::assertInstanceOf(TestTagInterface::class, $tag); } diff --git a/tests/integration/FactoryClass/file1.yml b/tests/integration/FactoryClass/file1.yml index 088c7f8..60395a6 100644 --- a/tests/integration/FactoryClass/file1.yml +++ b/tests/integration/FactoryClass/file1.yml @@ -1,3 +1,6 @@ +parameters: + my_custom_argument: "custom_value" + services: factory.service: class: Silktide\Syringe\IntegrationTests\FactoryClass\ExampleFactoryService @@ -9,6 +12,10 @@ services: class: Silktide\Syringe\IntegrationTests\FactoryClass\ExampleClass factoryService: "@factory.service" factoryMethod: "create" + calls: + - method: setCustomParameter + arguments: + - "%my_custom_argument%" service.example: class: Silktide\Syringe\IntegrationTests\FactoryClass\ServiceExample @@ -20,6 +27,10 @@ services: arguments: - "@service.example" - "#tagtag" + calls: + - method: setCustomParameter + arguments: + - "%my_custom_argument%" TagClass1: class: Silktide\Syringe\IntegrationTests\Examples\TagClass1