8000 [DependencyInjection] A decorated service should not keep the autowiring types by chalasr · Pull Request #20267 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] A decorated service should not keep the autowiring types #20267

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

Merged
Merged
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 < 8000 details-menu class="select-menu-modal position-absolute" style="z-index: 99;" src="/symfony/symfony/pull/20267/show_toc?base_sha=5a08a32f30569f61970077ba1d9b47f72d39f343&sha1=5a08a32f30569f61970077ba1d9b47f72d39f343&sha2=5951378727ae4f26107899282f5ff9b89a3aa277" preload>
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ public function process(ContainerBuilder $container)
} else {
$decoratedDefinition = $container->getDefinition($inner);
$definition->setTags($decoratedDefinition->getTags(), $definition->getTags());
$definition->setAutowiringTypes(array_merge($decoratedDefinition->getAutowiringTypes(), $definition->getAutowiringTypes()));
$public = $decoratedDefinition->isPublic();
$decoratedDefinition->setPublic(false);
$decoratedDefinition->setTags(array());
$decoratedDefinition->setAutowiringTypes(array());
Copy link
Member

Choose a reason for hiding this comment

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

I think we should first add the old value to the decorating service. What do you think?

8000

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, done

$container->setDefinition($renamedId, $decoratedDefinition);
}

Expand Down
< 8000 tr data-hunk="4f12301731747d48db7f1be5e3eb668859db8b2713c53dab3f658d28d6fb8fb4" class="show-top-border">
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,27 @@ public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinitio
$this->assertEquals(array('name' => 'bar'), $container->getDefinition('baz')->getTags());
}

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

$container
->register('parent')
->addAutowiringType('Bar')
;

$container
->register('child')
->setDecoratedService('parent')
->addAutowiringType('Foo')
;

$this->process($container);

$this->assertEquals(array('Bar', 'Foo'), $container->getDefinition('child')->getAutowiringTypes());
$this->assertEmpty($container->getDefinition('child.inner')->getAutowiringTypes());
}

protected function process(ContainerBuilder $container)
{
$repeatedPass = new DecoratorServicePass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,11 @@ public function testProcessMergeAutowiringTypes()

$this->process($container);

$def = $container->getDefinition('child');
$this->assertEquals(array('Foo', 'Bar'), $def->getAutowiringTypes());
$childDef = $container->getDefinition('child');
$this->assertEquals(array('Foo', 'Bar'), $childDef->getAutowiringTypes());

$parentDef = $container->getDefinition('parent');
$this->assertSame(array('Foo'), $parentDef->getAutowiringTypes());
}

protected function process(ContainerBuilder $container)
Expand Down
0