File tree 6 files changed +37
-11
lines changed
DependencyInjection/Compiler
Tests/DependencyInjection
6 files changed +37
-11
lines changed Original file line number Diff line number Diff line change 24
24
*/
25
25
class AddCacheClearerPass extends BaseAddCacheClearerPass
26
26
{
27
+ public function __construct ()
28
+ {
29
+ parent ::__construct ('cache_clearer ' , 'kernel.cache_clearer ' );
30
+ }
27
31
}
Original file line number Diff line number Diff line change 24
24
*/
25
25
class AddCacheWarmerPass extends BaseAddCacheWarmerPass
26
26
{
27
+ public function __construct ()
28
+ {
29
+ parent ::__construct ('cache_warmer ' , 'kernel.cache_warmer ' );
30
+ }
27
31
}
Original file line number Diff line number Diff line change @@ -88,8 +88,8 @@ public function build(ContainerBuilder $container)
88
88
$ this ->addCompilerPassIfExists ($ container , AddConsoleCommandPass::class);
89
89
$ container ->addCompilerPass (new TranslatorPass ());
90
90
$ container ->addCompilerPass (new LoggingTranslatorPass ());
91
- $ container ->addCompilerPass (new AddCacheWarmerPass ());
92
- $ container ->addCompilerPass (new AddCacheClearerPass ());
91
+ $ container ->addCompilerPass (new AddCacheWarmerPass (' cache_warmer ' , ' kernel.cache_warmer ' ));
92
+ $ container ->addCompilerPass (new AddCacheClearerPass (' cache_clearer ' , ' kernel.cache_clearer ' ));
93
93
$ container ->addCompilerPass (new AddExpressionLanguageProvidersPass ());
94
94
$ container ->addCompilerPass (new TranslationExtractorPass ());
95
95
$ container ->addCompilerPass (new TranslationDumperPass ());
Original file line number Diff line number Diff line change 22
22
*/
23
23
class AddCacheClearerPass implements CompilerPassInterface
24
24
{
25
+ private $ tag ;
26
+ private $ serviceName ;
27
+
28
+ public function __construct ($ serviceName , $ tag )
29
+ {
30
+ $ this ->serviceName = $ serviceName ;
31
+ $ this ->tag = $ tag ;
32
+ }
33
+
25
34
/**
26
35
* {@inheritdoc}
27
36
*/
28
37
public function process (ContainerBuilder $ container )
29
38
{
30
- if (!$ container ->hasDefinition (' cache_clearer ' )) {
39
+ if (!$ container ->hasDefinition ($ this -> serviceName )) {
31
40
return ;
32
41
}
33
42
34
43
$ clearers = array ();
35
- foreach ($ container ->findTaggedServiceIds (' kernel.cache_clearer ' ) as $ id => $ attributes ) {
44
+ foreach ($ container ->findTaggedServiceIds ($ this -> tag ) as $ id => $ attributes ) {
36
45
$ clearers [] = new Reference ($ id );
37
46
}
38
47
39
- $ container ->getDefinition (' cache_clearer ' )->replaceArgument (0 , $ clearers );
48
+ $ container ->getDefinition ($ this -> serviceName )->replaceArgument (0 , $ clearers );
40
49
}
41
50
}
Original file line number Diff line number Diff line change @@ -24,21 +24,30 @@ class AddCacheWarmerPass implements CompilerPassInterface
24
24
{
25
25
use PriorityTaggedServiceTrait;
26
26
27
+ private $ tag ;
28
+ private $ serviceName ;
29
+
30
+ public function __construct ($ serviceName , $ tag )
31
+ {
32
+ $ this ->serviceName = $ serviceName ;
33
+ $ this ->tag = $ tag ;
34
+ }
35
+
27
36
/**
28
37
* {@inheritdoc}
29
38
*/
30
39
public function process (ContainerBuilder $ container )
31
40
{
32
- if (!$ container ->hasDefinition (' cache_warmer ' )) {
41
+ if (!$ container ->hasDefinition ($ this -> serviceName )) {
33
42
return ;
34
43
}
35
44
36
- $ warmers = $ this ->findAndSortTaggedServices (' kernel.cache_warmer ' , $ container );
45
+ $ warmers = $ this ->findAndSortTaggedServices ($ this -> tag , $ container );
37
46
38
47
if (empty ($ warmers )) {
39
48
return ;
40
49
}
41
50
42
- $ container ->getDefinition (' cache_warmer ' )->replaceArgument (0 , $ warmers );
51
+ $ container ->getDefinition ($ this -> serviceName )->replaceArgument (0 , $ warmers );
43
52
}
44
53
}
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ public function testThatCacheWarmersAreProcessedInPriorityOrder()
48
48
new Reference ('my_cache_warmer_service3 ' ),
49
49
));
50
50
51
- $ addCacheWarmerPass = new AddCacheWarmerPass ();
51
+ $ addCacheWarmerPass = new AddCacheWarmerPass (' cache_warmer ' , ' kernel.cache_warmer ' );
52
52
$ addCacheWarmerPass ->process ($ container );
53
53
}
54
54
@@ -65,7 +65,7 @@ public function testThatCompilerPassIsIgnoredIfThereIsNoCacheWarmerDefinition()
65
65
->will ($ this ->returnValue (false ));
66
66
$ definition ->expects ($ this ->never ())->method ('replaceArgument ' );
67
67
68
- $ addCacheWarmerPass = new AddCacheWarmerPass ();
68
+ $ addCacheWarmerPass = new AddCacheWarmerPass (' cache_warmer ' , ' kernel.cache_warmer ' );
69
69
$ addCacheWarmerPass ->process ($ container );
70
70
}
71
71
@@ -85,7 +85,7 @@ public function testThatCacheWarmersMightBeNotDefined()
85
85
86
86
$ definition ->expects ($ this ->never ())->method ('replaceArgument ' );
87
87
88
- $ addCacheWarmerPass = new AddCacheWarmerPass ();
88
+ $ addCacheWarmerPass = new AddCacheWarmerPass (' cache_warmer ' , ' kernel.cache_warmer ' );
89
89
$ addCacheWarmerPass ->process ($ container );
90
90
}
91
91
}
You can’t perform that action at this time.
0 commit comments