@@ -33,36 +33,16 @@ public function load(array $configs, ContainerBuilder $container)
33
33
$ loader ->load ('cache_control_listener.xml ' );
34
34
}
35
35
36
- if (!empty ($ config ['rules ' ])) {
37
- $ this ->loadRules ($ container , $ config );
38
- }
39
-
40
36
if (isset ($ config ['proxy_client ' ])) {
41
- $ container ->setParameter ($ this ->getAlias ().'.invalidators ' , $ config ['invalidators ' ]);
42
37
$ this ->loadProxyClient ($ container , $ loader , $ config ['proxy_client ' ]);
38
+ }
43
39
44
- $ loader ->load ('cache_manager.xml ' );
45
-
46
- if ($ config ['tag_listener ' ]['enabled ' ]) {
47
- // true or auto
48
- if (class_exists ('\Symfony\Component\ExpressionLanguage\ExpressionLanguage ' )) {
49
- $ loader ->load ('tag_listener.xml ' );
50
- } elseif (true === $ config ['tag_listener ' ]['enabled ' ]) {
51
- // silently skip if set to auto
52
- throw new \RuntimeException ('The TagListener requires symfony/expression-language ' );
53
- }
54
- }
40
+ if ($ config ['cache_manager ' ]['enabled ' ] && isset ($ config ['proxy_client ' ])) {
41
+ $ this ->loadCacheManager ($ container , $ loader , $ config ['cache_manager ' ]);
42
+ }
55
43
56
- if (version_compare (Kernel::VERSION , '2.4.0 ' , '>= ' )) {
57
- $ container
58
- ->getDefinition ('fos_http_cache.command.invalidate_path ' )
59
- ->addTag ('console.command ' )
60
- ;
61
- }
62
- } elseif (!empty ($ config ['invalidators ' ])) {
63
- throw new InvalidConfigurationException ('You need to configure a proxy client to use the invalidators. ' );
64
- } elseif (true === $ config ['tag_listener ' ]['enabled ' ]) {
65
- throw new InvalidConfigurationException ('You need to configure a proxy client to use the tag listener. ' );
44
+ if (!empty ($ config ['rules ' ])) {
45
+ $ this ->loadRules ($ container , $ config );
66
46
}
67
47
68
48
if ($ config ['user_context ' ]['enabled ' ]) {
@@ -78,14 +58,13 @@ public function load(array $configs, ContainerBuilder $container)
78
58
79
59
/**
80
60
* @param ContainerBuilder $container
81
- * @param $config
61
+ * @param array $config
62
+ *
63
+ * @throws InvalidConfigurationException
82
64
*/
83
- protected function loadRules (ContainerBuilder $ container , $ config )
65
+ protected function loadRules (ContainerBuilder $ container , array $ config )
84
66
{
85
67
foreach ($ config ['rules ' ] as $ rule ) {
86
- if (!isset ($ rule ['headers ' ])) {
87
- continue ;
88
- }
89
68
$ match = $ rule ['match ' ];
90
69
91
70
$ match ['ips ' ] = (empty ($ match ['ips ' ])) ? null : $ match ['ips ' ];
@@ -111,11 +90,27 @@ protected function loadRules(ContainerBuilder $container, $config)
111
90
$ extraCriteria
112
91
);
113
92
93
+ $ tags = array (
94
+ 'tags ' => $ rule ['tags ' ],
95
+ 'expressions ' => $ rule ['tag_expressions ' ],
96
+ );
97
+ if (count ($ tags ['tags ' ]) || count ($ tags ['expressions ' ])) {
98
+ if (!$ container ->hasDefinition ($ this ->getAlias () . '.event_listener.tag ' )) {
99
+ throw new InvalidConfigurationException ('To configure tags, you need to have the tag event listener enabled, requiring symfony/expression-language ' );
100
+ }
101
+
102
+ $ container
103
+ ->getDefinition ($ this ->getAlias () . '.event_listener.tag ' )
104
+ ->addMethodCall ('addRule ' , array ($ ruleMatcher , $ tags ))
105
+ ;
106
+ }
114
107
115
- $ container
116
- ->getDefinition ($ this ->getAlias () . '.event_listener.cache_control ' )
117
- ->addMethodCall ('add ' , array ($ ruleMatcher , $ rule ['headers ' ]))
118
- ;
108
+ if (isset ($ rule ['headers ' ])) {
109
+ $ container
110
+ ->getDefinition ($ this ->getAlias () . '.event_listener.cache_control ' )
111
+ ->addMethodCall ('addRule ' , array ($ ruleMatcher , $ rule ['headers ' ]))
112
+ ;
113
+ }
119
114
}
120
115
}
121
116
@@ -209,6 +204,37 @@ protected function loadVarnish(ContainerBuilder $container, XmlFileLoader $loade
209
204
$ container ->setParameter ($ this ->getAlias () . '.proxy_client.varnish.base_url ' , $ config ['base_url ' ]);
210
205
}
211
206
207
+ protected function loadCacheManager (ContainerBuilder $ container , XmlFileLoader $ loader , array $ config )
208
+ {
209
+ $ container ->setParameter ($ this ->getAlias ().'.cache_manager.route_invalidators ' , $ config ['route_invalidators ' ]);
210
+
211
+ $ container ->setParameter (
212
+ $ this ->getAlias () . '.cache_manager.additional_status ' ,
213
+ isset ($ config ['additional_status ' ]) ? $ config ['additional_status ' ] : array ()
214
+ );
215
+ $ container ->setParameter (
216
+ $ this ->getAlias () . '.cache_manager.match_response ' ,
217
+ isset ($ config ['match_response ' ]) ? $ config ['match_response ' ] : null
218
+ );
219
+ $ loader ->load ('cache_manager.xml ' );
220
+ if (version_compare (Kernel::VERSION , '2.4.0 ' , '>= ' )) {
221
+ $ container
222
+ ->getDefinition ('fos_http_cache.command.invalidate_path ' )
223
+ ->addTag ('console.command ' )
224
+ ;
225
+ }
226
+
227
+ if ($ config ['tag_listener ' ]['enabled ' ]) {
228
+ // true or auto
229
+ if (class_exists ('\Symfony\Component\ExpressionLanguage\ExpressionLanguage ' )) {
230
+ $ loader ->load ('tag_listener.xml ' );
231
+ } elseif (true === $ config ['tag_listener ' ]['enabled ' ]) {
232
+ // silently skip if set to auto
233
+ throw new InvalidConfigurationException ('The TagListener requires symfony/expression-language ' );
234
+ }
235
+ }
236
+ }
237
+
212
238
private function validateUrl ($ url , $ msg )
213
239
{
214
240
if (false === strpos ($ url , ':// ' )) {
0 commit comments