From 6ebcddd55dbe8f79ded956d9ddb31f2ac9c21afb Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Tue, 2 Jun 2015 15:43:57 +0200 Subject: [PATCH] [DependencyInjection] Fixed resolving of service configurators containing Definition objects --- .../Component/DependencyInjection/ContainerBuilder.php | 8 +++++++- .../DependencyInjection/Tests/ContainerBuilderTest.php | 7 +++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index b7104a06e746..3ee0c322c636 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -982,7 +982,13 @@ public function createService(Definition $definition, $id, $tryProxy = true) if ($callable = $definition->getConfigurator()) { if (is_array($callable)) { - $callable[0] = $callable[0] instanceof Reference ? $this->get((string) $callable[0]) : $parameterBag->resolveValue($callable[0]); + $callable[0] = $parameterBag->resolveValue($callable[0]); + + if ($callable[0] instanceof Reference) { + $callable[0] = $this->get((string) $callable[0], $callable[0]->getInvalidBehavior()); + } elseif ($callable[0] instanceof Definition) { + $callable[0] = $this->createService($callable[0], null); + } } if (!is_callable($callable)) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 5f6fdd1d1715..1e3f10340596 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -405,9 +405,12 @@ public function testCreateServiceConfigurator() $builder->register('foo3', 'Bar\FooClass')->setConfigurator(array(new Reference('baz'), 'configure')); $this->assertTrue($builder->get('foo3')->configured, '->createService() calls the configurator'); - $builder->register('foo4', 'Bar\FooClass')->setConfigurator('foo'); + $builder->register('foo4', 'Bar\FooClass')->setConfigurator(array($builder->getDefinition('baz'), 'configure')); + $this->assertTrue($builder->get('foo4')->configured, '->createService() calls the configurator'); + + $builder->register('foo5', 'Bar\FooClass')->setConfigurator('foo'); try { - $builder->get('foo4'); + $builder->get('foo5'); $this->fail('->createService() throws an InvalidArgumentException if the configure callable is not a valid callable'); } catch (\InvalidArgumentException $e) { $this->assertEquals('The configure callable for class "Bar\FooClass" is not a callable.', $e->getMessage(), '->createService() throws an InvalidArgumentException if the configure callable is not a valid callable');