Skip to content

Commit

Permalink
[DI] Allow defining bindings on ChildDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed May 15, 2018
1 parent 4c38b4d commit 1c3b105
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
8 changes: 0 additions & 8 deletions src/Symfony/Component/DependencyInjection/ChildDefinition.php
Expand Up @@ -121,14 +121,6 @@ public function setInstanceofConditionals(array $instanceof)
{
throw new BadMethodCallException('A ChildDefinition cannot have instanceof conditionals set on it.');
}

/**
* @internal
*/
public function setBindings(array $bindings)
{
throw new BadMethodCallException('A ChildDefinition cannot have bindings set on it.');
}
}

class_alias(ChildDefinition::class, DefinitionDecorator::class);
Expand Up @@ -103,7 +103,7 @@ private function doResolveDefinition(ChildDefinition $definition)
$def->setAutowired($parentDef->isAutowired());
$def->setChanges($parentDef->getChanges());

$def->setBindings($parentDef->getBindings());
$def->setBindings($definition->getBindings() + $parentDef->getBindings());

// overwrite with values specified in the decorator
$changes = $definition->getChanges();
Expand Down
Expand Up @@ -382,6 +382,27 @@ public function testProcessSetsArguments()
$this->assertSame(array(2, 1, 'foo' => 3), $def->getArguments());
}

public function testBindings()
{
$container = new ContainerBuilder();

$container->register('parent', 'stdClass')
->setBindings(array('a' => '1', 'b' => '2'))
;

$child = $container->setDefinition('child', new ChildDefinition('parent'))
->setBindings(array('b' => 'B', 'c' => 'C'))
;

$this->process($container);

$bindings = array();
foreach ($container->getDefinition('child')->getBindings() as $k => $v) {
$bindings[$k] = $v->getValues()[0];
}
$this->assertEquals(array('b' => 'B', 'c' => 'C', 'a' => '1'), $bindings);
}

public function testSetAutoconfiguredOnServiceIsParent()
{
$container = new ContainerBuilder();
Expand Down

0 comments on commit 1c3b105

Please sign in to comment.