25
25
class ReplaceAliasByActualDefinitionPass extends AbstractRecursivePass
26
26
{
27
27
private $ replacements ;
28
+ private $ autoAliasServicePass ;
29
+
30
+ /**
31
+ * @internal to be removed in Symfony 6.0
32
+ *
33
+ * @return $this
34
+ */
35
+ public function setAutoAliasServicePass (AutoAliasServicePass $ autoAliasServicePass ): self
36
+ {
37
+ $ this ->autoAliasServicePass = $ autoAliasServicePass ;
38
+
39
+ return $ this ;
40
+ }
28
41
29
42
/**
30
43
* Process the Container to replace aliases with service definitions.
@@ -36,15 +49,25 @@ public function process(ContainerBuilder $container)
36
49
// First collect all alias targets that need to be replaced
37
50
$ seenAliasTargets = [];
38
51
$ replacements = [];
52
+
53
+ $ privateAliases = $ this ->autoAliasServicePass ? $ this ->autoAliasServicePass ->getPrivateAliases () : [];
54
+ foreach ($ privateAliases as $ target ) {
55
+ $ target ->setDeprecated ('symfony/dependency-injection ' , '5.4 ' , 'Accessing the "%alias_id%" service directly from the container is deprecated, use dependency injection instead. ' );
56
+ }
57
+
39
58
foreach ($ container ->getAliases () as $ definitionId => $ target ) {
40
59
$ targetId = (string ) $ target ;
41
60
// Special case: leave this target alone
42
61
if ('service_container ' === $ targetId ) {
43
62
continue ;
44
63
}
45
- // Check if target needs to be replaces
64
+ // Check if target needs to be replaced
46
65
if (isset ($ replacements [$ targetId ])) {
47
66
$ container ->setAlias ($ definitionId , $ replacements [$ targetId ])->setPublic ($ target ->isPublic ());
67
+
68
+ if ($ target ->isDeprecated ()) {
69
+ $ container ->getAlias ($ definitionId )->setDeprecated (...array_values ($ target ->getDeprecation ('%alias_id% ' )));
70
+ }
48
71
}
49
72
// No need to process the same target twice
50
73
if (isset ($ seenAliasTargets [$ targetId ])) {
@@ -69,6 +92,10 @@ public function process(ContainerBuilder $container)
69
92
$ container ->setDefinition ($ definitionId , $ definition );
70
93
$ container ->removeDefinition ($ targetId );
71
94
$ replacements [$ targetId ] = $ definitionId ;
95
+
96
+ if ($ target ->isPublic () && $ target ->isDeprecated ()) {
97
+ $ definition ->addTag ('container.private ' , $ target ->getDeprecation ('%service_id% ' ));
98
+ }
72
99
}
73
100
$ this ->replacements = $ replacements ;
74
101
0 commit comments