Skip to content

Commit f2a870d

Browse files
committed
[DependencyInjection] Fixed resolving of service configurators containing Definition objects
1 parent 3cacf5d commit f2a870d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

ContainerBuilder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,13 @@ public function createService(Definition $definition, $id, $tryProxy = true)
982982

983983
if ($callable = $definition->getConfigurator()) {
984984
if (is_array($callable)) {
985-
$callable[0] = $callable[0] instanceof Reference ? $this->get((string) $callable[0]) : $parameterBag->resolveValue($callable[0]);
985+
$callable[0] = $parameterBag->resolveValue($callable[0]);
986+
987+
if ($callable[0] instanceof Reference) {
988+
$callable[0] = $this->get((string) $callable[0], $callable[0]->getInvalidBehavior());
989+
} elseif ($callable[0] instanceof Definition) {
990+
$callable[0] = $this->createService($callable[0], null);
991+
}
986992
}
987993

988994
if (!is_callable($callable)) {

Tests/ContainerBuilderTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,12 @@ public function testCreateServiceConfigurator()
405405
$builder->register('foo3', 'Bar\FooClass')->setConfigurator(array(new Reference('baz'), 'configure'));
406406
$this->assertTrue($builder->get('foo3')->configured, '->createService() calls the configurator');
407407

408-
$builder->register('foo4', 'Bar\FooClass')->setConfigurator('foo');
408+
$builder->register('foo4', 'Bar\FooClass')->setConfigurator(array($builder->getDefinition('baz'), 'configure'));
409+
$this->assertTrue($builder->get('foo4')->configured, '->createService() calls the configurator');
410+
411+
$builder->register('foo5', 'Bar\FooClass')->setConfigurator('foo');
409412
try {
410-
$builder->get('foo4');
413+
$builder->get('foo5');
411414
$this->fail('->createService() throws an InvalidArgumentException if the configure callable is not a valid callable');
412415
} catch (\InvalidArgumentException $e) {
413416
$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');

0 commit comments

Comments
 (0)