@@ -33,36 +33,16 @@ public function load(array $configs, ContainerBuilder $container)
3333 $ loader ->load ('cache_control_listener.xml ' );
3434 }
3535
36- if (!empty ($ config ['rules ' ])) {
37- $ this ->loadRules ($ container , $ config );
38- }
39-
4036 if (isset ($ config ['proxy_client ' ])) {
41- $ container ->setParameter ($ this ->getAlias ().'.invalidators ' , $ config ['invalidators ' ]);
4237 $ this ->loadProxyClient ($ container , $ loader , $ config ['proxy_client ' ]);
38+ }
4339
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+ }
5543
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 );
6646 }
6747
6848 if ($ config ['user_context ' ]['enabled ' ]) {
@@ -78,14 +58,13 @@ public function load(array $configs, ContainerBuilder $container)
7858
7959 /**
8060 * @param ContainerBuilder $container
81- * @param $config
61+ * @param array $config
62+ *
63+ * @throws InvalidConfigurationException
8264 */
83- protected function loadRules (ContainerBuilder $ container , $ config )
65+ protected function loadRules (ContainerBuilder $ container , array $ config )
8466 {
8567 foreach ($ config ['rules ' ] as $ rule ) {
86- if (!isset ($ rule ['headers ' ])) {
87- continue ;
88- }
8968 $ match = $ rule ['match ' ];
9069
9170 $ match ['ips ' ] = (empty ($ match ['ips ' ])) ? null : $ match ['ips ' ];
@@ -111,11 +90,27 @@ protected function loadRules(ContainerBuilder $container, $config)
11190 $ extraCriteria
11291 );
11392
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+ }
114107
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+ }
119114 }
120115 }
121116
@@ -209,6 +204,37 @@ protected function loadVarnish(ContainerBuilder $container, XmlFileLoader $loade
209204 $ container ->setParameter ($ this ->getAlias () . '.proxy_client.varnish.base_url ' , $ config ['base_url ' ]);
210205 }
211206
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+
212238 private function validateUrl ($ url , $ msg )
213239 {
214240 if (false === strpos ($ url , ':// ' )) {
0 commit comments