Skip to content

[DependencyInjection] fixed definition loosing property shared when decorated by a parent definition #16926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ private function resolveDefinition(ContainerBuilder $container, DefinitionDecora
// these attributes are always taken from the child
$def->setAbstract($definition->isAbstract());
$def->setScope($definition->getScope(false), false);
$def->setShared($definition->isShared());
$def->setTags($definition->getTags());

return $def;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ public function testProcessDoesNotCopyScope()
$this->assertEquals(ContainerInterface::SCOPE_CONTAINER, $def->getScope());
}

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

$container
->register('parent')
->setShared(false)
;

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

$this->process($container);

$def = $container->getDefinition('child');
$this->assertTrue($def->isShared());
}

public function testProcessDoesNotCopyTags()
{
$container = new ContainerBuilder();
Expand Down Expand Up @@ -139,6 +158,25 @@ public function testProcessDoesNotCopyDecoratedService()
$this->assertNull($def->getDecoratedService());
}

public function testProcessDoesNotDropShared()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a testProcessDoesNotCopyShared, to mimic what we have for the scope

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. testProcessDoesNotCopyShared has been added.

{
$container = new ContainerBuilder();

$container
->register('parent')
;

$container
->setDefinition('child', new DefinitionDecorator('parent'))
->setShared(false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO you should put this setShared(false) in the definition of the parent service in order to test if we pass the same shared value to their childrens.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dosten the shared flag is always taken from the child (same than the scope in 2.x, as this is the replacement for the scope)

;

$this->process($container);

$def = $container->getDefinition('child');
$this->assertFalse($def->isShared());
}

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