[DependencyInjection] Fixed resolving of service configurators containing Definition objects
This commit is contained in:
parent
d23d3c9b93
commit
6ebcddd55d
@ -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)) {
|
||||
|
@ -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');
|
||||
|
Reference in New Issue
Block a user