Skip to content

Commit

Permalink
[DependencyInjection] Fixed resolving of service configurators contai…
Browse files Browse the repository at this point in the history
…ning Definition objects
  • Loading branch information
webmozart committed Jun 11, 2015
1 parent d23d3c9 commit 6ebcddd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Expand Up @@ -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)) {
Expand Down
Expand Up @@ -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');
Expand Down

0 comments on commit 6ebcddd

Please sign in to comment.