[DependencyInjection] Fixed resolving of service configurators containing Definition objects

This commit is contained in:
Bernhard Schussek 2015-06-02 15:43:57 +02:00
parent d23d3c9b93
commit 6ebcddd55d
2 changed files with 12 additions and 3 deletions

View File

@ -982,7 +982,13 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
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)) {

View File

@ -405,9 +405,12 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
$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');