28
28
*/
29
29
class CachePoolPass implements CompilerPassInterface
30
30
{
31
- private $ cachePoolTag ;
32
- private $ kernelResetTag ;
33
- private $ cacheClearerId ;
34
- private $ cachePoolClearerTag ;
35
- private $ cacheSystemClearerId ;
36
- private $ cacheSystemClearerTag ;
37
- private $ reverseContainerId ;
38
- private $ reversibleTag ;
39
- private $ messageHandlerId ;
40
-
41
- public function __construct (string $ cachePoolTag = 'cache.pool ' , string $ kernelResetTag = 'kernel.reset ' , string $ cacheClearerId = 'cache.global_clearer ' , string $ cachePoolClearerTag = 'cache.pool.clearer ' , string $ cacheSystemClearerId = 'cache.system_clearer ' , string $ cacheSystemClearerTag = 'kernel.cache_clearer ' , string $ reverseContainerId = 'reverse_container ' , string $ reversibleTag = 'container.reversible ' , string $ messageHandlerId = 'cache.early_expiration_handler ' )
42
- {
43
- if (0 < \func_num_args ()) {
44
- trigger_deprecation ('symfony/cache ' , '5.3 ' , 'Configuring "%s" is deprecated. ' , __CLASS__ );
45
- }
46
-
47
- $ this ->cachePoolTag = $ cachePoolTag ;
48
- $ this ->kernelResetTag = $ kernelResetTag ;
49
- $ this ->cacheClearerId = $ cacheClearerId ;
50
- $ this ->cachePoolClearerTag = $ cachePoolClearerTag ;
51
- $ this ->cacheSystemClearerId = $ cacheSystemClearerId ;
52
- $ this ->cacheSystemClearerTag = $ cacheSystemClearerTag ;
53
- $ this ->reverseContainerId = $ reverseContainerId ;
54
- $ this ->reversibleTag = $ reversibleTag ;
55
- $ this ->messageHandlerId = $ messageHandlerId ;
56
- }
57
-
58
31
/**
59
32
* {@inheritdoc}
60
33
*/
@@ -78,7 +51,7 @@ public function process(ContainerBuilder $container)
78
51
'early_expiration_message_bus ' ,
79
52
'reset ' ,
80
53
];
81
- foreach ($ container ->findTaggedServiceIds ($ this -> cachePoolTag ) as $ id => $ tags ) {
54
+ foreach ($ container ->findTaggedServiceIds (' cache.pool ' ) as $ id => $ tags ) {
82
55
$ adapter = $ pool = $ container ->getDefinition ($ id );
83
56
if ($ pool ->isAbstract ()) {
84
57
continue ;
@@ -87,7 +60,7 @@ public function process(ContainerBuilder $container)
87
60
while ($ adapter instanceof ChildDefinition) {
88
61
$ adapter = $ container ->findDefinition ($ adapter ->getParent ());
89
62
$ class = $ class ?: $ adapter ->getClass ();
90
- if ($ t = $ adapter ->getTag ($ this -> cachePoolTag )) {
63
+ if ($ t = $ adapter ->getTag (' cache.pool ' )) {
91
64
$ tags [0 ] += $ t [0 ];
92
65
}
93
66
}
@@ -129,7 +102,7 @@ public function process(ContainerBuilder $container)
129
102
while ($ adapter instanceof ChildDefinition) {
130
103
$ adapter = $ container ->findDefinition ($ adapter ->getParent ());
131
104
$ chainedClass = $ chainedClass ?: $ adapter ->getClass ();
132
- if ($ t = $ adapter ->getTag ($ this -> cachePoolTag )) {
105
+ if ($ t = $ adapter ->getTag (' cache.pool ' )) {
133
106
$ chainedTags [0 ] += $ t [0 ];
134
107
}
135
108
}
@@ -167,19 +140,19 @@ public function process(ContainerBuilder $container)
167
140
// no-op
168
141
} elseif ('reset ' === $ attr ) {
169
142
if ($ tags [0 ][$ attr ]) {
170
- $ pool ->addTag ($ this -> kernelResetTag , ['method ' => $ tags [0 ][$ attr ]]);
143
+ $ pool ->addTag (' kernel.reset ' , ['method ' => $ tags [0 ][$ attr ]]);
171
144
}
172
145
} elseif ('early_expiration_message_bus ' === $ attr ) {
173
146
$ needsMessageHandler = true ;
174
147
$ pool ->addMethodCall ('setCallbackWrapper ' , [(new Definition (EarlyExpirationDispatcher::class))
175
148
->addArgument (new Reference ($ tags [0 ]['early_expiration_message_bus ' ]))
176
- ->addArgument (new Reference ($ this -> reverseContainerId ))
149
+ ->addArgument (new Reference (' reverse_container ' ))
177
150
->addArgument ((new Definition ('callable ' ))
178
151
->setFactory ([new Reference ($ id ), 'setCallbackWrapper ' ])
179
152
->addArgument (null )
180
153
),
181
154
]);
182
- $ pool ->addTag ($ this -> reversibleTag );
155
+ $ pool ->addTag (' container.reversible ' );
183
156
} elseif ('namespace ' !== $ attr || ArrayAdapter::class !== $ class ) {
184
157
$ argument = $ tags [0 ][$ attr ];
185
158
@@ -193,7 +166,7 @@ public function process(ContainerBuilder $container)
193
166
unset($ tags [0 ][$ attr ]);
194
167
}
195
168
if (!empty ($ tags [0 ])) {
196
- throw new InvalidArgumentException (sprintf ('Invalid "%s " tag for service "%s": accepted attributes are "clearer", "provider", "name", "namespace", "default_lifetime", "early_expiration_message_bus" and "reset", found "%s". ' , $ this -> cachePoolTag , $ id , implode ('", " ' , array_keys ($ tags [0 ]))));
169
+ throw new InvalidArgumentException (sprintf ('Invalid "cache.pool " tag for service "%s": accepted attributes are "clearer", "provider", "name", "namespace", "default_lifetime", "early_expiration_message_bus" and "reset", found "%s". ' , $ id , implode ('", " ' , array_keys ($ tags [0 ]))));
197
170
}
198
171
199
172
if (null !== $ clearer ) {
@@ -204,14 +177,14 @@ public function process(ContainerBuilder $container)
204
177
}
205
178
206
179
if (!$ needsMessageHandler ) {
207
- $ container ->removeDefinition ($ this -> messageHandlerId );
180
+ $ container ->removeDefinition (' cache.early_expiration_handler ' );
208
181
}
209
182
210
- $ notAliasedCacheClearerId = $ this -> cacheClearerId ;
211
- while ($ container ->hasAlias ($ this -> cacheClearerId )) {
212
- $ this -> cacheClearerId = (string ) $ container ->getAlias ($ this -> cacheClearerId );
183
+ $ notAliasedCacheClearerId = $ aliasedCacheClearerId = ' cache.global_clearer ' ;
184
+ while ($ container ->hasAlias (' cache.global_clearer ' )) {
185
+ $ aliasedCacheClearerId = (string ) $ container ->getAlias (' cache.global_clearer ' );
213
186
}
214
- if ($ container ->hasDefinition ($ this -> cacheClearerId )) {
187
+ if ($ container ->hasDefinition ($ aliasedCacheClearerId )) {
215
188
$ clearers [$ notAliasedCacheClearerId ] = $ allPools ;
216
189
}
217
190
@@ -222,10 +195,10 @@ public function process(ContainerBuilder $container)
222
195
} else {
223
196
$ clearer ->setArgument (0 , $ pools );
224
197
}
225
- $ clearer ->addTag ($ this -> cachePoolClearerTag );
198
+ $ clearer ->addTag (' cache.pool.clearer ' );
226
199
227
- if ($ this -> cacheSystemClearerId === $ id ) {
228
- $ clearer ->addTag ($ this -> cacheSystemClearerTag );
200
+ if (' cache.system_clearer ' === $ id ) {
201
+ $ clearer ->addTag (' kernel.cache_clearer ' );
229
202
}
230
203
}
231
204
0 commit comments