Skip to content

Commit

Permalink
bug #13750 [DependencyInjection] Fixed decoration of service for serv…
Browse files Browse the repository at this point in the history
…ice with parent (hason)

This PR was merged into the 2.6 branch.

Discussion
----------

[DependencyInjection] Fixed decoration of service for service with parent

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

0b8b58c [DependencyInjection] Fixed decoration of service for service with parent
  • Loading branch information
fabpot committed Jun 25, 2015
2 parents dac1552 + 0b8b58c commit b812eb0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Expand Up @@ -119,6 +119,14 @@ private function resolveDefinition($id, DefinitionDecorator $definition)
if (isset($changes['lazy'])) {
$def->setLazy($definition->isLazy());
}
if (isset($changes['decorated_service'])) {
$decoratedService = $definition->getDecoratedService();
if (null === $decoratedService) {
$def->setDecoratedService($decoratedService);
} else {
$def->setDecoratedService($decoratedService[0], $decoratedService[1]);
}
}

// merge arguments
foreach ($definition->getArguments() as $k => $v) {
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/DependencyInjection/DefinitionDecorator.php
Expand Up @@ -170,6 +170,16 @@ public function setLazy($boolean)
return parent::setLazy($boolean);
}

/**
* {@inheritdoc}
*/
public function setDecoratedService($id, $renamedId = null)
{
$this->changes['decorated_service'] = true;

return parent::setDecoratedService($id, $renamedId);
}

/**
* Gets an argument to pass to the service constructor/factory method.
*
Expand Down
Expand Up @@ -117,6 +117,25 @@ public function testProcessDoesNotCopyTags()
$this->assertEquals(array(), $def->getTags());
}

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

$container
->register('parent')
->setDecoratedService('foo')
;

$container
->setDefinition('child', new DefinitionDecorator('parent'))
;

$this->process($container);

$def = $container->getDefinition('child');
$this->assertNull($def->getDecoratedService());
}

public function testProcessHandlesMultipleInheritance()
{
$container = new ContainerBuilder();
Expand Down Expand Up @@ -173,6 +192,21 @@ public function testSetLazyOnServiceIsParent()
$this->assertTrue($container->getDefinition('child1')->isLazy());
}

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

$container->register('parent', 'stdClass');

$container->setDefinition('child1', new DefinitionDecorator('parent'))
->setDecoratedService('foo', 'foo_inner')
;

$this->process($container);

$this->assertEquals(array('foo', 'foo_inner'), $container->getDefinition('child1')->getDecoratedService());
}

protected function process(ContainerBuilder $container)
{
$pass = new ResolveDefinitionTemplatesPass();
Expand Down

0 comments on commit b812eb0

Please sign in to comment.