1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ConfigCacheBundle package. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2015-2016 Yahoo Japan Corporation |
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 YahooJapan\ConfigCacheBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
15
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
16
|
|
|
use Symfony\Component\HttpKernel\EventListener\LocaleListener; |
17
|
|
|
use Symfony\Component\HttpKernel\KernelEvents; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* This is the class that validates and merges configuration from your app/config files |
21
|
|
|
* |
22
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} |
23
|
|
|
*/ |
24
|
|
|
class Configuration implements ConfigurationInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
25 |
|
public function getConfigTreeBuilder() |
30
|
|
|
{ |
31
|
25 |
|
$treeBuilder = new TreeBuilder(); |
32
|
25 |
|
$rootNode = $treeBuilder->root('yahoo_japan_config_cache'); |
33
|
|
|
$rootNode |
34
|
25 |
|
->children() |
35
|
25 |
|
->booleanNode('cache_warmup')->defaultValue(true)->end() |
36
|
25 |
|
->booleanNode('cache_restore')->defaultValue(false)->end() |
37
|
25 |
|
->arrayNode('locale') |
38
|
25 |
|
->children() |
39
|
25 |
|
->booleanNode('enabled')->defaultValue(false)->end() |
40
|
25 |
|
->arrayNode('locales') |
41
|
25 |
|
->prototype('scalar')->end() |
42
|
25 |
|
->end() |
43
|
25 |
|
->integerNode('listener_priority') |
44
|
25 |
|
->defaultValue(0) |
45
|
25 |
|
->validate() |
46
|
|
|
// priority must be less than LocaleListener priority |
47
|
|
|
->ifTrue(function ($priority) { |
48
|
4 |
|
return $priority >= Configuration::getPriorityMax(); |
49
|
25 |
|
}) |
50
|
25 |
|
->thenInvalid('LocaleListener priority[%s] must be less than LocaleListener priority['.Configuration::getPriorityMax().']') |
51
|
25 |
|
->end() |
52
|
25 |
|
->end() |
53
|
25 |
|
->scalarNode('loader')->defaultValue(null)->end() |
54
|
25 |
|
->end() |
55
|
25 |
|
->validate() |
56
|
25 |
|
->ifTrue(function ($locale) { |
57
|
6 |
|
return $locale['enabled'] && $locale['locales'] === array(); |
58
|
25 |
|
}) |
59
|
25 |
|
->thenInvalid('yahoo_japan_config_cache.locale.locales must be configured.') |
60
|
25 |
|
->end() |
61
|
25 |
|
->end() |
62
|
25 |
|
->end() |
63
|
|
|
; |
64
|
|
|
|
65
|
25 |
|
return $treeBuilder; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Gets a listener priority max. |
70
|
|
|
* |
71
|
|
|
* The priority max is a LocaleListener priority. |
72
|
|
|
* |
73
|
|
|
* @return int |
74
|
|
|
*/ |
75
|
25 |
|
public static function getPriorityMax() |
76
|
|
|
{ |
77
|
25 |
|
$events = LocaleListener::getSubscribedEvents(); |
78
|
|
|
|
79
|
25 |
|
return $events[KernelEvents::REQUEST][0][1]; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|