Skip to content

Commit 0c78585

Browse files
feature #40468 Deprecate configuring tag names and service ids in compiler passes (nicolas-grekas)
This PR was merged into the 5.3-dev branch. Discussion ---------- Deprecate configuring tag names and service ids in compiler passes | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | - | License | MIT | Doc PR | - This PR is aimed at reducing the code complexity by hardcoding the name of tags and service ids that compiler passes have to deal with. I think making these names configurable only adds boilerplate and maintenance overhead for no benefit: - for the practice: the need to use a pass with a renamed tag/id should be extremely rare (do yo know any?) - for the theory: a decorating pass could still rename before/after the processing, so this use case is still supported. Side note: I skipped updating changelog+upgrade files. This would be just noise to me (nobody uses this possibility anyway ;) ) Commits ------- 6fe82d8be7 Deprecate configuring tag names and service ids in compiler passes
2 parents 712005c + b0b463f commit 0c78585

8 files changed

+27
-13
lines changed

Compiler/AliasDeprecatedPublicServicesPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ final class AliasDeprecatedPublicServicesPass extends AbstractRecursivePass
2323

2424
public function __construct(string $tagName = 'container.private')
2525
{
26+
if (0 < \func_num_args()) {
27+
trigger_deprecation('symfony/dependency-injection', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
28+
}
29+
2630
$this->tagName = $tagName;
2731
}
2832

Compiler/AttributeAutoconfigurationPass.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919
*/
2020
final class AttributeAutoconfigurationPass implements CompilerPassInterface
2121
{
22-
private $ignoreAttributesTag;
23-
24-
public function __construct(string $ignoreAttributesTag = 'container.ignore_attributes')
25-
{
26-
$this->ignoreAttributesTag = $ignoreAttributesTag;
27-
}
28-
2922
public function process(ContainerBuilder $container): void
3023
{
3124
if (80000 > \PHP_VERSION_ID) {
@@ -37,7 +30,7 @@ public function process(ContainerBuilder $container): void
3730
foreach ($container->getDefinitions() as $id => $definition) {
3831
if (!$definition->isAutoconfigured()
3932
|| $definition->isAbstract()
40-
|| $definition->hasTag($this->ignoreAttributesTag)
33+
|| $definition->hasTag('container.ignore_attributes')
4134
|| !($reflector = $container->getReflectionClass($definition->getClass(), false))
4235
) {
4336
continue;

Compiler/DecoratorServicePass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class DecoratorServicePass extends AbstractRecursivePass
3030

3131
public function __construct(?string $innerId = '.inner')
3232
{
33+
if (0 < \func_num_args()) {
34+
trigger_deprecation('symfony/dependency-injection', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
35+
}
36+
3337
$this->innerId = $innerId;
3438
}
3539

Compiler/RegisterAutoconfigureAttributesPass.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@
2424
*/
2525
final class RegisterAutoconfigureAttributesPass implements CompilerPassInterface
2626
{
27-
private $ignoreAttributesTag;
2827
private $registerForAutoconfiguration;
2928

30-
public function __construct(string $ignoreAttributesTag = 'container.ignore_attributes')
29+
public function __construct()
3130
{
3231
if (80000 > \PHP_VERSION_ID) {
3332
return;
3433
}
3534

36-
$this->ignoreAttributesTag = $ignoreAttributesTag;
37-
3835
$parseDefinitions = new \ReflectionMethod(YamlFileLoader::class, 'parseDefinitions');
3936
$parseDefinitions->setAccessible(true);
4037
$yamlLoader = $parseDefinitions->getDeclaringClass()->newInstanceWithoutConstructor();
@@ -80,7 +77,7 @@ public function process(ContainerBuilder $container)
8077

8178
public function accept(Definition $definition): bool
8279
{
83-
return 80000 <= \PHP_VERSION_ID && $definition->isAutoconfigured() && !$definition->hasTag($this->ignoreAttributesTag);
80+
return 80000 <= \PHP_VERSION_ID && $definition->isAutoconfigured() && !$definition->hasTag('container.ignore_attributes');
8481
}
8582

8683
public function processClass(ContainerBuilder $container, \ReflectionClass $class)

Compiler/RegisterReverseContainerPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class RegisterReverseContainerPass implements CompilerPassInterface
2828

2929
public function __construct(bool $beforeRemoving, string $serviceId = 'reverse_container', string $tagName = 'container.reversible')
3030
{
31+
if (1 < \func_num_args()) {
32+
trigger_deprecation('symfony/dependency-injection', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
33+
}
34+
3135
$this->beforeRemoving = $beforeRemoving;
3236
$this->serviceId = $serviceId;
3337
$this->tagName = $tagName;

Compiler/ResolveDecoratorStackPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class ResolveDecoratorStackPass implements CompilerPassInterface
2828

2929
public function __construct(string $tag = 'container.stack')
3030
{
31+
if (0 < \func_num_args()) {
32+
trigger_deprecation('symfony/dependency-injection', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
33+
}
34+
3135
$this->tag = $tag;
3236
}
3337

Compiler/ResolveHotPathPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class ResolveHotPathPass extends AbstractRecursivePass
2828

2929
public function __construct(string $tagName = 'container.hot_path')
3030
{
31+
if (0 < \func_num_args()) {
32+
trigger_deprecation('symfony/dependency-injection', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
33+
}
34+
3135
$this->tagName = $tagName;
3236
}
3337

Compiler/ResolveNoPreloadPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class ResolveNoPreloadPass extends AbstractRecursivePass
2929

3030
public function __construct(string $tagName = 'container.no_preload')
3131
{
32+
if (0 < \func_num_args()) {
33+
trigger_deprecation('symfony/dependency-injection', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
34+
}
35+
3236
$this->tagName = $tagName;
3337
}
3438

0 commit comments

Comments
 (0)