Skip to content

Commit 1a409e5

Browse files
committed
bug #14835 [DependencyInjection] Fixed resolving of service configurators containing Definition objects (webmozart)
This PR was merged into the 2.7 branch. Discussion ---------- [DependencyInjection] Fixed resolving of service configurators containing Definition objects | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14834 | License | MIT | Doc PR | - Commits ------- 6ebcddd [DependencyInjection] Fixed resolving of service configurators containing Definition objects
2 parents 7fb10f2 + f2a870d commit 1a409e5

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)