Completed
Push — master ( ca6270...ba5ea5 )
by David
42:39 queued 14:41
created

Configuration::addMatch()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 55
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 48
CRAP Score 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 55
ccs 48
cts 48
cp 1
rs 9.7692
cc 3
eloc 52
nc 1
nop 1
crap 3

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCacheBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
15
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
16
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
17
use Symfony\Component\Config\Definition\ConfigurationInterface;
18
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
19
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
20
21
/**
22
 * This class contains the configuration information for the bundle
23
 *
24
 * This information is solely responsible for how the different configuration
25
 * sections are normalized, and merged.
26
 *
27
 * @author David de Boer <[email protected]>
28
 * @author David Buchmann <[email protected]>
29
 */
30
class Configuration implements ConfigurationInterface
31
{
32
    /**
33
     * @var bool
34
     */
35
    private $debug;
36
37
    /**
38
     * @param Boolean $debug Whether to use the debug mode
39
     */
40 32
    public function __construct($debug)
41
    {
42 32
        $this->debug = $debug;
43 32
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48 32
    public function getConfigTreeBuilder()
49
    {
50 32
        $treeBuilder = new TreeBuilder();
51 32
        $rootNode = $treeBuilder->root('fos_http_cache');
52
53
        $rootNode
54 32
            ->validate()
55
                ->ifTrue(function ($v) {
56 30
                    return $v['cache_manager']['enabled']
57 30
                        && !isset($v['proxy_client'])
58 30
                        && !isset($v['cache_manager']['custom_proxy_client'])
59 30
                    ;
60 32
                })
61
                ->then(function ($v) {
62 7
                    if ('auto' === $v['cache_manager']['enabled']) {
63 6
                        $v['cache_manager']['enabled'] = false;
64
65 6
                        return $v;
66
                    }
67 1
                    throw new InvalidConfigurationException('You need to configure a proxy_client or specify a custom_proxy_client to use the cache_manager.');
68 32
                })
69 32
            ->end()
70 32
            ->validate()
71
                ->ifTrue(function ($v) {return $v['tags']['enabled'] && !$v['cache_manager']['enabled'];})
72
                ->then(function ($v) {
73 8
                    if ('auto' === $v['tags']['enabled']) {
74 7
                        $v['tags']['enabled'] = false;
75
76 7
                        return $v;
77
                    }
78 1
                    throw new InvalidConfigurationException('You need to configure a proxy_client to get the cache_manager needed for tag handling.');
79 32
                })
80 32
            ->end()
81 32
            ->validate()
82
                ->ifTrue(function ($v) {return $v['invalidation']['enabled'] && !$v['cache_manager']['enabled'];})
83
                ->then(function ($v) {
84 7
                    if ('auto' === $v['invalidation']['enabled']) {
85 6
                        $v['invalidation']['enabled'] = false;
86
87 6
                        return $v;
88
                    }
89 1
                    throw new InvalidConfigurationException('You need to configure a proxy_client to get the cache_manager needed for invalidation handling.');
90 32
                })
91 32
            ->end()
92 32
            ->validate()
93 View Code Duplication
                ->ifTrue(function ($v) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94 27
                    return isset($v['test'])
95 27
                        && $v['test']['client']['varnish']['enabled']
96 27
                        && !isset($v['proxy_client']['varnish']);
97 32
                    })
98 View Code Duplication
                ->then(function ($v) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
                    if ('auto' === $v['test']['client']['varnish']['enabled']) {
100
                        $v['test']['client']['varnish']['enabled'] = false;
101
102
                        return $v;
103
                    }
104
                    throw new InvalidConfigurationException('You need to configure the Varnish proxy_client to use the Varnish test client');
105 32
                })
106 32
            ->end()
107 32
            ->validate()
108 View Code Duplication
                ->ifTrue(function ($v) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
109 27
                    if (isset($v['test'])) {
110 1
                        return $v['test']['client']['nginx']['enabled'] && !isset($v['proxy_client']['nginx']);
111
                    }
112 32
                })
113 View Code Duplication
                ->then(function ($v) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114 1
                    if ('auto' === $v['test']['client']['nginx']['enabled']) {
115 1
                        $v['test']['client']['nginx']['enabled'] = false;
116
117 1
                        return $v;
118
                    }
119
                    throw new InvalidConfigurationException('You need to configure the Nginx proxy_client to use the Nginx test client');
120 32
                })
121 32
            ->end()
122 32
            ->validate()
123 32
                ->ifTrue(
124
                    function ($v) {
125 27
                        return $v['user_context']['logout_handler']['enabled']
126 27
                            && !isset($v['proxy_client']);
127
                    }
128 32
                )
129
                ->then(function ($v) {
130 7
                    if ('auto' === $v['user_context']['logout_handler']['enabled']) {
131 7
                        $v['user_context']['logout_handler']['enabled'] = false;
132
133 7
                        return $v;
134
                    }
135
                    throw new InvalidConfigurationException('You need to configure a proxy_client for the logout_handler.');
136 32
                })
137
        ;
138
139 32
        $this->addCacheControlSection($rootNode);
140 32
        $this->addProxyClientSection($rootNode);
141 32
        $this->addCacheManagerSection($rootNode);
142 32
        $this->addTagSection($rootNode);
143 32
        $this->addInvalidationSection($rootNode);
144 32
        $this->addUserContextListenerSection($rootNode);
145 32
        $this->addFlashMessageSection($rootNode);
146 32
        $this->addTestSection($rootNode);
147 32
        $this->addDebugSection($rootNode);
148
149 32
        return $treeBuilder;
150
    }
151
152
    /**
153
     * Cache header control main section.
154
     *
155
     * @param ArrayNodeDefinition $rootNode
156
     */
157 32
    private function addCacheControlSection(ArrayNodeDefinition $rootNode)
158
    {
159
        $rules = $rootNode
160 32
            ->children()
161 32
                ->arrayNode('cache_control')
162 32
                    ->fixXmlConfig('rule')
163 32
                    ->children()
164 32
                        ->arrayNode('defaults')
165 32
                            ->addDefaultsIfNotSet()
166 32
                            ->children()
167 32
                                ->booleanNode('overwrite')
168 32
                                    ->info('Whether to overwrite existing cache headers')
169 32
                                    ->defaultFalse()
170 32
                                ->end()
171 32
                            ->end()
172 32
                        ->end()
173 32
                        ->arrayNode('rules')
174 32
                            ->prototype('array')
175 32
                                ->children();
176
177 32
        $this->addMatch($rules);
178
        $rules
179 32
            ->arrayNode('headers')
180 32
                ->isRequired()
181
                // todo validate there is some header defined
182 32
                ->children()
183 32
                    ->enumNode('overwrite')
184 32
                        ->info('Whether to overwrite cache headers for this rule, defaults to the cache_control.defaults.overwrite setting')
185 32
                        ->values(array('default', true, false))
186 32
                        ->defaultValue('default')
187 32
                    ->end()
188 32
                    ->arrayNode('cache_control')
189 32
                        ->info('Add the specified cache control directives.')
190 32
                        ->children()
191 32
                            ->scalarNode('max_age')->end()
192 32
                            ->scalarNode('s_maxage')->end()
193 32
                            ->booleanNode('private')->end()
194 32
                            ->booleanNode('public')->end()
195 32
                            ->booleanNode('must_revalidate')->end()
196 32
                            ->booleanNode('proxy_revalidate')->end()
197 32
                            ->booleanNode('no_transform')->end()
198 32
                            ->booleanNode('no_cache')->end()
199 32
                            ->scalarNode('stale_if_error')->end()
200 32
                            ->scalarNode('stale_while_revalidate')->end()
201 32
                        ->end()
202 32
                    ->end()
203 32
                    ->scalarNode('etag')
204 32
                        ->defaultValue(false)
205 32
                        ->info('Set a simple ETag which is just the md5 hash of the response body')
206 32
                    ->end()
207 32
                    ->scalarNode('last_modified')
208 32
                        ->validate()
209
                            ->ifTrue(function ($v) {
210 2
                                if (is_string($v)) {
211 2
                                    new \DateTime($v);
212 1
                                }
213
214 1
                                return false;
215 32
                            })
216 32
                            ->thenInvalid('') // this will never happen as new DateTime will throw an exception if $v is no date
217 32
                        ->end()
218 32
                        ->info('Set a default last modified timestamp if none is set yet. Value must be parseable by DateTime')
219 32
                    ->end()
220 32
                    ->scalarNode('reverse_proxy_ttl')
221 32
                        ->defaultNull()
222 32
                        ->info('Specify an X-Reverse-Proxy-TTL header with a time in seconds for a caching proxy under your control.')
223 32
                    ->end()
224 32
                    ->arrayNode('vary')
225
                        ->beforeNormalization()->ifString()->then(function ($v) { return preg_split('/\s*,\s*/', $v); })->end()
226 32
                        ->prototype('scalar')->end()
227 32
                        ->info('Define a list of additional headers on which the response varies.')
228 32
                    ->end()
229 32
                ->end()
230 32
            ->end()
231
        ;
232 32
    }
233
234
    /**
235
     * Shared configuration between cache control, tags and invalidation.
236
     *
237
     * @param NodeBuilder $rules
238
     */
239 32
    private function addMatch(NodeBuilder $rules)
240
    {
241
        $rules
242 32
            ->arrayNode('match')
243 32
                ->cannotBeOverwritten()
244 32
                ->isRequired()
245 32
                ->fixXmlConfig('method')
246 32
                ->fixXmlConfig('ip')
247 32
                ->fixXmlConfig('attribute')
248 32
                ->validate()
249
                    ->ifTrue(function ($v) {return !empty($v['additional_cacheable_status']) && !empty($v['match_response']);})
250 32
                    ->thenInvalid('You may not set both additional_cacheable_status and match_response.')
251 32
                ->end()
252 32
                ->validate()
253
                    ->ifTrue(function ($v) {return !empty($v['match_response']) && !class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage');})
254 32
                    ->thenInvalid('Configured a match_response but ExpressionLanguage is not available')
255 32
                ->end()
256 32
                ->children()
257 32
                    ->scalarNode('path')
258 32
                        ->defaultNull()
259 32
                        ->info('Request path.')
260 32
                    ->end()
261 32
                    ->scalarNode('host')
262 32
                        ->defaultNull()
263 32
                        ->info('Request host name.')
264 32
                    ->end()
265 32
                    ->arrayNode('methods')
266
                        ->beforeNormalization()->ifString()->then(function ($v) { return preg_split('/\s*,\s*/', $v); })->end()
267 32
                        ->useAttributeAsKey('name')
268 32
                        ->prototype('scalar')->end()
269 32
                        ->info('Request HTTP methods.')
270 32
                    ->end()
271 32
                    ->arrayNode('ips')
272
                        ->beforeNormalization()->ifString()->then(function ($v) { return preg_split('/\s*,\s*/', $v); })->end()
273 32
                        ->useAttributeAsKey('name')
274 32
                        ->prototype('scalar')->end()
275 32
                        ->info('List of client IPs.')
276 32
                    ->end()
277 32
                    ->arrayNode('attributes')
278 32
                        ->useAttributeAsKey('name')
279 32
                        ->prototype('scalar')->end()
280 32
                        ->info('Regular expressions on request attributes.')
281 32
                    ->end()
282 32
                    ->arrayNode('additional_cacheable_status')
283 32
                        ->prototype('scalar')->end()
284 32
                        ->info('Additional response HTTP status codes that will match.')
285 32
                    ->end()
286 32
                    ->scalarNode('match_response')
287 32
                        ->defaultNull()
288 32
                        ->info('Expression to decide whether response should be matched. Replaces HTTP code check and additional_cacheable_status.')
289 32
                    ->end()
290 32
                ->end()
291 32
            ->end()
292
        ;
293 32
    }
294
295 32
    private function addProxyClientSection(ArrayNodeDefinition $rootNode)
296
    {
297
        $rootNode
298 32
            ->children()
299 32
                ->arrayNode('proxy_client')
300 32
                    ->children()
301 32
                        ->enumNode('default')
302 32
                            ->values(array('varnish', 'nginx', 'symfony'))
303 32
                            ->info('If you configure more than one proxy client, specify which client is the default.')
304 32
                        ->end()
305 32
                        ->arrayNode('varnish')
306 32
                            ->fixXmlConfig('server')
307 32
                            ->children()
308 32
                                ->arrayNode('servers')
309
                                    ->beforeNormalization()->ifString()->then(function ($v) { return preg_split('/\s*,\s*/', $v); })->end()
310 32
                                    ->useAttributeAsKey('name')
311 32
                                    ->isRequired()
312 32
                                    ->requiresAtLeastOneElement()
313 32
                                    ->prototype('scalar')->end()
314 32
                                    ->info('Addresses of the hosts Varnish is running on. May be hostname or ip, and with :port if not the default port 80.')
315 32
                                ->end()
316 32
                                ->scalarNode('base_url')
317 32
                                    ->defaultNull()
318 32
                                    ->info('Default host name and optional path for path based invalidation.')
319 32
                                ->end()
320 32
                                ->scalarNode('guzzle_client')
321 32
                                    ->defaultNull()
322 32
                                    ->info('Guzzle service to use for customizing the requests.')
323 32
                                ->end()
324 32
                            ->end()
325 32
                        ->end()
326
327 32
                        ->arrayNode('nginx')
328 32
                            ->fixXmlConfig('server')
329 32
                            ->children()
330 32
                                ->arrayNode('servers')
331
                                    ->beforeNormalization()->ifString()->then(function ($v) { return preg_split('/\s*,\s*/', $v); })->end()
332 32
                                    ->useAttributeAsKey('name')
333 32
                                    ->isRequired()
334 32
                                    ->requiresAtLeastOneElement()
335 32
                                    ->prototype('scalar')->end()
336 32
                                    ->info('Addresses of the hosts Nginx is running on. May be hostname or ip, and with :port if not the default port 80.')
337 32
                                ->end()
338 32
                                ->scalarNode('base_url')
339 32
                                    ->defaultNull()
340 32
                                    ->info('Default host name and optional path for path based invalidation.')
341 32
                                ->end()
342 32
                                ->scalarNode('guzzle_client')
343 32
                                    ->defaultNull()
344 32
                                    ->info('Guzzle service to use for customizing the requests.')
345 32
                                ->end()
346 32
                                ->scalarNode('purge_location')
347 32
                                    ->defaultValue('')
348 32
                                    ->info('Path to trigger the purge on Nginx for different location purge.')
349 32
                                ->end()
350 32
                            ->end()
351 32
                        ->end()
352
353 32
                        ->arrayNode('symfony')
354 32
                            ->fixXmlConfig('server')
355 32
                            ->children()
356 32
                                ->arrayNode('servers')
357
                                    ->beforeNormalization()->ifString()->then(function ($v) { return preg_split('/\s*,\s*/', $v); })->end()
358 32
                                    ->useAttributeAsKey('name')
359 32
                                    ->isRequired()
360 32
                                    ->requiresAtLeastOneElement()
361 32
                                    ->prototype('scalar')->end()
362 32
                                    ->info('Addresses of the hosts Symfony HttpCache is running on. May be hostname or ip, and with :port if not the default port 80.')
363 32
                                ->end()
364 32
                                ->scalarNode('base_url')
365 32
                                    ->defaultNull()
366 32
                                    ->info('Default host name and optional path for path based invalidation.')
367 32
                                ->end()
368 32
                                ->scalarNode('guzzle_client')
369 32
                                    ->defaultNull()
370 32
                                    ->info('Guzzle service to use for customizing the requests.')
371 32
                                ->end()
372 32
                            ->end()
373 32
                        ->end()
374
375 32
                    ->end()
376 32
                ->end()
377 32
            ->end();
378 32
    }
379
380 32
    private function addTestSection(ArrayNodeDefinition $rootNode)
381
    {
382
        $rootNode
383 32
            ->children()
384 32
                ->arrayNode('test')
385 32
                    ->children()
386 32
                        ->scalarNode('cache_header')
387 32
                            ->defaultValue('X-Cache')
388 32
                            ->info('HTTP cache hit/miss header')
389 32
                        ->end()
390 32
                        ->arrayNode('proxy_server')
391 32
                            ->info('Configure how caching proxy will be run in your tests')
392 32
                            ->children()
393 32
                                ->enumNode('default')
394 32
                                    ->values(array('varnish', 'nginx'))
395 32
                                    ->info('If you configure more than one proxy server, specify which client is the default.')
396 32
                                ->end()
397 32
                                ->arrayNode('varnish')
398 32
                                    ->children()
399 32
                                        ->scalarNode('config_file')->isRequired()->end()
400 32
                                        ->scalarNode('binary')->defaultValue('varnishd')->end()
401 32
                                        ->integerNode('port')->defaultValue(6181)->end()
402 32
                                        ->scalarNode('ip')->defaultValue('127.0.0.1')->end()
403 32
                                    ->end()
404 32
                                ->end()
405 32
                                ->arrayNode('nginx')
406 32
                                    ->children()
407 32
                                        ->scalarNode('config_file')->isRequired()->end()
408 32
                                        ->scalarNode('binary')->defaultValue('nginx')->end()
409 32
                                        ->integerNode('port')->defaultValue(8080)->end()
410 32
                                        ->scalarNode('ip')->defaultValue('127.0.0.1')->end()
411 32
                                    ->end()
412 32
                                ->end()
413 32
                            ->end()
414 32
                        ->end()
415 32
                        ->arrayNode('client')
416 32
                            ->addDefaultsIfNotSet()
417 32
                            ->children()
418 32
                                ->enumNode('default')
419 32
                                    ->values(array('varnish', 'nginx'))
420 32
                                    ->info('If you configure more than one proxy client, specify which client is the default.')
421 32
                                ->end()
422 32
                                ->arrayNode('varnish')
423 32
                                    ->addDefaultsIfNotSet()
424 32
                                    ->canBeEnabled()
425 32
                                    ->children()
426 32
                                        ->enumNode('enabled')
427 32
                                            ->values(array(true, false, 'auto'))
428 32
                                            ->defaultValue('auto')
429 32
                                            ->info('Whether to enable the Varnish test client.')
430 32
                                        ->end()
431 32
                                    ->end()
432 32
                                ->end()
433 32
                                ->arrayNode('nginx')
434 32
                                    ->addDefaultsIfNotSet()
435 32
                                    ->canBeEnabled()
436 32
                                    ->children()
437 32
                                        ->enumNode('enabled')
438 32
                                            ->values(array(true, false, 'auto'))
439 32
                                            ->defaultValue('auto')
440 32
                                            ->info('Whether to enable the Nginx test client.')
441 32
                                        ->end()
442 32
                                    ->end()
443 32
                                ->end()
444 32
                            ->end()
445 32
                        ->end()
446 32
                    ->end()
447 32
                ->end()
448 32
            ->end();
449 32
    }
450
451
    /**
452
     * Cache manager main section
453
     *
454
     * @param ArrayNodeDefinition $rootNode
455
     */
456 32
    private function addCacheManagerSection(ArrayNodeDefinition $rootNode)
457
    {
458
        $rootNode
459 32
            ->children()
460 32
                ->arrayNode('cache_manager')
461 32
                    ->addDefaultsIfNotSet()
462 32
                    ->beforeNormalization()
463 32
                        ->ifArray()
464
                        ->then(function ($v) {
465 5
                            $v['enabled'] = isset($v['enabled']) ? $v['enabled'] : true;
466
467 5
                            return $v;
468 32
                        })
469 32
                    ->end()
470 32
                    ->info('Configure the cache manager. Needs a proxy_client to be configured.')
471 32
                    ->children()
472 32
                        ->enumNode('enabled')
473 32
                            ->values(array(true, false, 'auto'))
474 32
                            ->defaultValue('auto')
475 32
                            ->info('Allows to disable the invalidation manager. Enabled by default if you configure a proxy client.')
476 32
                        ->end()
477 32
                        ->scalarNode('custom_proxy_client')
478 32
                            ->info('Service name of a custom proxy client to use. If you configure a proxy client, that client will be used by default.')
479 32
                        ->end()
480 32
                        ->enumNode('generate_url_type')
481 32
                            ->values(array(
482 32
                                'auto',
483 32
                                UrlGeneratorInterface::ABSOLUTE_PATH,
484 32
                                UrlGeneratorInterface::ABSOLUTE_URL,
485 32
                                UrlGeneratorInterface::NETWORK_PATH,
486 32
                                UrlGeneratorInterface::RELATIVE_PATH,
487 32
                            ))
488 32
                            ->defaultValue('auto')
489 32
                            ->info('Set what URLs to generate on invalidate/refresh Route. Auto means path if base_url is set on the default proxy client, full URL otherwise.')
490 32
                        ->end()
491 32
                    ->end()
492
        ;
493 32
    }
494
495 32
    private function addTagSection(ArrayNodeDefinition $rootNode)
496
    {
497
        $rules = $rootNode
498 32
            ->children()
499 32
                ->arrayNode('tags')
500 32
                    ->addDefaultsIfNotSet()
501 32
                    ->fixXmlConfig('rule')
502 32
                    ->children()
503 32
                        ->enumNode('enabled')
504 32
                            ->values(array(true, false, 'auto'))
505 32
                            ->defaultValue('auto')
506 32
                            ->info('Allows to disable the event subscriber for tag configuration and annotations when your project does not use the annotations. Enabled by default if you configured the cache manager.')
507 32
                        ->end()
508 32
                        ->scalarNode('expression_language')
509 32
                            ->defaultNull()
510 32
                            ->info('Service name of a custom ExpressionLanugage to use.')
511 32
                        ->end()
512 32
                        ->scalarNode('header')
513 32
                            ->defaultValue('X-Cache-Tags')
514 32
                            ->info('HTTP header that contains cache tags')
515 32
                        ->end()
516 32
                        ->arrayNode('rules')
517 32
                            ->prototype('array')
518 32
                                ->fixXmlConfig('tag')
519 32
                                ->fixXmlConfig('tag_expression')
520 32
                                ->validate()
521
                                    ->ifTrue(function ($v) {return !empty($v['tag_expressions']) && !class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage');})
522 32
                                    ->thenInvalid('Configured a tag_expression but ExpressionLanugage is not available')
523 32
                                ->end()
524 32
                                ->children();
525
526 32
        $this->addMatch($rules);
527
528
        $rules
529 32
            ->arrayNode('tags')
530 32
                ->prototype('scalar')
531 32
                ->info('Tags to add to the response on safe requests, to invalidate on unsafe requests')
532 32
            ->end()->end()
533 32
            ->arrayNode('tag_expressions')
534 32
                ->prototype('scalar')
535 32
                ->info('Tags to add to the response on safe requests, to invalidate on unsafe requests')
536 32
            ->end()
537
        ;
538 32
    }
539
540 32
    private function addInvalidationSection(ArrayNodeDefinition $rootNode)
541
    {
542
        $rules = $rootNode
543 32
            ->children()
544 32
                ->arrayNode('invalidation')
545 32
                    ->fixXmlConfig('rule')
546 32
                    ->addDefaultsIfNotSet()
547 32
                    ->children()
548 32
                        ->enumNode('enabled')
549 32
                            ->values(array(true, false, 'auto'))
550 32
                            ->defaultValue('auto')
551 32
                            ->info('Allows to disable the listener for invalidation. Enabled by default if the cache manager is configured. When disabled, the cache manager is no longer flushed automatically.')
552 32
                        ->end()
553 32
                        ->scalarNode('expression_language')
554 32
                            ->defaultNull()
555 32
                            ->info('Service name of a custom ExpressionLanugage to use.')
556 32
                        ->end()
557 32
                        ->arrayNode('rules')
558 32
                            ->info('Set what requests should invalidate which target routes.')
559 32
                            ->prototype('array')
560 32
                                ->fixXmlConfig('route')
561 32
                                ->children();
562
563 32
        $this->addMatch($rules);
564
        $rules
565 32
            ->arrayNode('routes')
566 32
                ->isRequired()
567 32
                ->requiresAtLeastOneElement()
568 32
                ->useAttributeAsKey('name')
569 32
                ->info('Target routes to invalidate when request is matched')
570 32
                ->prototype('array')
571 32
                    ->children()
572 32
                        ->booleanNode('ignore_extra_params')->defaultTrue()->end()
573 32
                    ->end()
574 32
                ->end()
575 32
            ->end();
576 32
    }
577
578
    /**
579
     * User context main section.
580
     *
581
     * @param ArrayNodeDefinition $rootNode
582
     */
583 32
    private function addUserContextListenerSection(ArrayNodeDefinition $rootNode)
584
    {
585
        $rootNode
586 32
            ->children()
587 32
                ->arrayNode('user_context')
588 32
                    ->info('Listener that returns the request for the user context hash as early as possible.')
589 32
                    ->addDefaultsIfNotSet()
590 32
                    ->canBeEnabled()
591 32
                    ->fixXmlConfig('user_identifier_header')
592 32
                    ->children()
593 32
                        ->arrayNode('match')
594 32
                            ->addDefaultsIfNotSet()
595 32
                            ->children()
596 32
                                ->scalarNode('matcher_service')
597 32
                                    ->defaultValue('fos_http_cache.user_context.request_matcher')
598 32
                                    ->info('Service id of a request matcher that tells whether the request is a context hash request.')
599 32
                                ->end()
600 32
                                ->scalarNode('accept')
601 32
                                    ->defaultValue('application/vnd.fos.user-context-hash')
602 32
                                    ->info('Specify the accept HTTP header used for context hash requests.')
603 32
                                ->end()
604 32
                                ->scalarNode('method')
605 32
                                    ->defaultNull()
606 32
                                    ->info('Specify the HTTP method used for context hash requests.')
607 32
                                ->end()
608 32
                            ->end()
609 32
                        ->end()
610 32
                        ->scalarNode('hash_cache_ttl')
611 32
                            ->defaultValue(0)
612 32
                            ->info('Cache the response for the hash for the specified number of seconds. Setting this to 0 will not cache those responses at all.')
613 32
                        ->end()
614 32
                        ->arrayNode('user_identifier_headers')
615 32
                            ->prototype('scalar')->end()
616 32
                            ->defaultValue(array('Cookie', 'Authorization'))
617 32
                            ->info('List of headers that contains the unique identifier for the user in the hash request.')
618 32
                        ->end()
619 32
                        ->scalarNode('user_hash_header')
620 32
                            ->defaultValue('X-User-Context-Hash')
621 32
                            ->info('Name of the header that contains the hash information for the context.')
622 32
                        ->end()
623 32
                        ->booleanNode('role_provider')
624 32
                            ->defaultFalse()
625 32
                            ->info('Whether to enable a provider that automatically adds all roles of the current user to the context.')
626 32
                        ->end()
627 32
                        ->arrayNode('logout_handler')
628 32
                            ->addDefaultsIfNotSet()
629 32
                            ->canBeEnabled()
630 32
                            ->children()
631 32
                                ->enumNode('enabled')
632 32
                                    ->values(array(true, false, 'auto'))
633 32
                                    ->defaultValue('auto')
634 32
                                    ->info('Whether to enable the user context logout handler.')
635 32
                                ->end()
636 32
                            ->end()
637 32
                        ->end()
638 32
                    ->end()
639 32
                ->end()
640 32
            ->end()
641
        ;
642 32
    }
643
644 32
    private function addFlashMessageSection(ArrayNodeDefinition $rootNode)
645
    {
646
        $rootNode
647 32
            ->children()
648 32
                ->arrayNode('flash_message')
649 32
                    ->canBeUnset()
650 32
                    ->canBeEnabled()
651 32
                    ->info('Activate the flash message listener that puts flash messages into a cookie.')
652 32
                    ->children()
653 32
                        ->scalarNode('name')
654 32
                            ->defaultValue('flashes')
655 32
                            ->info('Name of the cookie to set for flashes.')
656 32
                        ->end()
657 32
                        ->scalarNode('path')
658 32
                            ->defaultValue('/')
659 32
                            ->info('Cookie path validity.')
660 32
                        ->end()
661 32
                        ->scalarNode('host')
662 32
                            ->defaultNull()
663 32
                            ->info('Cookie host name validity.')
664 32
                        ->end()
665 32
                        ->scalarNode('secure')
666 32
                            ->defaultFalse()
667 32
                            ->info('Whether the cookie should only be transmitted over a secure HTTPS connection from the client.')
668 32
                        ->end()
669 32
                    ->end()
670 32
                ->end()
671 32
            ->end();
672 32
    }
673
674 32
    private function addDebugSection(ArrayNodeDefinition $rootNode)
675
    {
676
        $rootNode
677 32
            ->children()
678 32
                ->arrayNode('debug')
679 32
                ->addDefaultsIfNotSet()
680 32
                ->canBeEnabled()
681 32
                ->children()
682 32
                    ->booleanNode('enabled')
683 32
                        ->defaultValue($this->debug)
684 32
                        ->info('Whether to send a debug header with the response to trigger a caching proxy to send debug information. If not set, defaults to kernel.debug.')
685 32
                    ->end()
686 32
                    ->scalarNode('header')
687 32
                        ->defaultValue('X-Cache-Debug')
688 32
                        ->info('The header to send if debug is true.')
689 32
                    ->end()
690 32
                ->end()
691 32
            ->end()
692 32
        ->end();
693 32
    }
694
}
695