10000 [DependencyInjection] Don't ignore attributes on the actual decorator by HypeMC · Pull Request #50595 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Don't ignore attributes on the actual decorator #50595

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 1 commit into from
Jul 7, 2023
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[DependencyInjection] Don't ignore attributes on the actual decorator
  • Loading branch information
HypeMC committed Jun 7, 2023
commit fdd2ec251e7ee9a95be7b4c54ddbd3b63d770d95
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private function processDefinition(ContainerBuilder $container, string $id, Defi
$instanceofDef->setAbstract(true)->setParent($parent ?: '.abstract.instanceof.'.$id);
$parent = '.instanceof.'.$interface.'.'.$key.'.'.$id;
$container->setDefinition($parent, $instanceofDef);
$instanceofTags[] = $instanceofDef->getTags();
$instanceofTags[] = [$interface, $instanceofDef->getTags()];
$instanceofBindings = $instanceofDef->getBindings() + $instanceofBindings;

foreach ($instanceofDef->getMethodCalls() as $methodCall) {
Expand Down Expand Up @@ -126,8 +126,9 @@ private function processDefinition(ContainerBuilder $container, string $id, Defi
// Don't add tags to service decorators
$i = \count($instanceofTags);
while (0 <= --$i) {
foreach ($instanceofTags[$i] as $k => $v) {
if (null === $definition->getDecoratedService() || \in_array($k, $tagsToKeep, true)) {
[$interface, $tags] = $instanceofTags[$i];
foreach ($tags as $k => $v) {
if (null === $definition->getDecoratedService() || $interface === $definition->getClass() || \in_array($k, $tagsToKeep, true)) {
foreach ($v as $v) {
if ($definition->hasTag($k) && \in_array($v, $definition->getTag($k))) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,26 @@ public function testDecoratorsAreNotAutomaticallyTagged()
$decorator->setDecoratedService('decorated');
$decorator->setInstanceofConditionals([
parent::class => (new ChildDefinition(''))->addTag('tag'),
self::class => (new ChildDefinition(''))->addTag('other-tag'),
]);
$decorator->setAutoconfigured(true);
$decorator->addTag('manual');

$container->registerForAutoconfiguration(parent::class)
->addTag('tag')
;
$container->registerForAutoconfiguration(self::class)
->addTag('last-tag')
;

(new ResolveInstanceofConditionalsPass())->process($container);
(new ResolveChildDefinitionsPass())->process($container);

$this->assertSame(['manual' => [[]]], $container->getDefinition('decorator')->getTags());
$this->assertSame([
'manual' => [[]],
'other-tag' => [[]],
'last-tag' => [[]],
], $container->getDefinition('decorator')->getTags());
}

public function testDecoratorsKeepBehaviorDescribingTags()
Expand Down
0