Skip to content

Commit f1dc422

Browse files
committed
feature #37243 [DependencyInjection] Resolve parameters in tag arguments (rpkamp)
This PR was squashed before being merged into the 5.2-dev branch. Discussion ---------- [DependencyInjection] Resolve parameters in tag arguments | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #35337 | License | MIT | Doc PR | None, yet, will follow if this is accepted Arguably this could be a BC break if people are actively relying on parameters not being resolved in tag parameters, although I can't come up with a sensible use case for that scenario. Commits ------- 3dba1fe [DependencyInjection] Resolve parameters in tag arguments
2 parents 7aaf99d + 3dba1fe commit f1dc422

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/Symfony/Component/DependencyInjection/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* added `param()` and `abstract_arg()` in the PHP-DSL
88
* deprecated `Definition::setPrivate()` and `Alias::setPrivate()`, use `setPublic()` instead
9+
* added support for parameters in service tag arguments
910

1011
5.1.0
1112
-----

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ public function findTaggedServiceIds(string $name, bool $throwOnAbstract = false
12501250
if ($throwOnAbstract && $definition->isAbstract()) {
12511251
throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must not be abstract.', $id, $name));
12521252
}
1253-
$tags[$id] = $definition->getTag($name);
1253+
$tags[$id] = $this->parameterBag->resolveValue($definition->getTag($name));
12541254
}
12551255
}
12561256

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,22 @@ public function testfindTaggedServiceIds()
911911
$this->assertEquals([], $builder->findTaggedServiceIds('foobar'), '->findTaggedServiceIds() returns an empty array if there is annotated services');
912912
}
913913

914+
public function testResolveTagAttributtes()
915+
{
916+
$builder = new ContainerBuilder();
917+
$builder->getParameterBag()->add(['foo_argument' => 'foo']);
918+
919+
$builder
920+
->register('foo', 'Bar\FooClass')
921+
->addTag('foo', ['foo' => '%foo_argument%'])
922+
;
923+
$this->assertEquals($builder->findTaggedServiceIds('foo'), [
924+
'foo' => [
925+
['foo' => 'foo'],
926+
],
927+
], '->findTaggedServiceIds() replaces parameters in tag attributes');
928+
}
929+
914930
public function testFindUnusedTags()
915931
{
916932
$builder = new ContainerBuilder();

0 commit comments

Comments
 (0)