1 | <?php |
||
21 | class Configuration implements ConfigurationInterface |
||
22 | { |
||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | */ |
||
26 | public function getConfigTreeBuilder() |
||
27 | { |
||
28 | $self = $this; |
||
29 | $treeBuilder = new TreeBuilder(); |
||
30 | $rootNode = $treeBuilder->root('maikuro_distributed_configuration'); |
||
31 | |||
32 | $supportedStores = ['dbal', 'predis', 'redis', 'json']; |
||
33 | |||
34 | $normalization = function ($conf) use ($self) { |
||
35 | |||
36 | $conf['type'] = $self->resolveNodeType($conf); |
||
37 | |||
38 | return $conf; |
||
39 | }; |
||
40 | |||
41 | $rootNode |
||
42 | ->children() |
||
43 | ->arrayNode('store') |
||
44 | ->beforeNormalization() |
||
45 | ->ifTrue(function ($v) { |
||
46 | return !isset($v['type']); |
||
47 | }) |
||
48 | ->then($normalization) |
||
49 | ->end() |
||
50 | ->children() |
||
51 | ->scalarNode('type') |
||
52 | ->validate() |
||
53 | ->ifNotInArray($supportedStores) |
||
54 | ->thenInvalid('The store %s is not supported. Please choose one of '.json_encode($supportedStores)) |
||
55 | ->end() |
||
56 | ->end() |
||
57 | ->append($this->addRedisNode()) |
||
58 | ->append($this->addPredisNode()) |
||
59 | ->append($this->addDbalNode()) |
||
60 | ->append($this->addJsonFileNode()) |
||
61 | ->end() |
||
62 | ->end() |
||
63 | ->arrayNode('cache') |
||
64 | ->addDefaultsIfNotSet() |
||
65 | ->children() |
||
66 | ->scalarNode('enabled')->defaultFalse()->end() |
||
67 | ->scalarNode('service_id')->defaultNull()->end() |
||
68 | ->scalarNode('default_ttl')->defaultValue('3600')->end() |
||
69 | ->end() |
||
70 | ->end() |
||
71 | ->end() |
||
72 | ; |
||
73 | |||
74 | return $treeBuilder; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param array $parameters |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | public function resolveNodeType(array $parameters) |
||
92 | |||
93 | /** |
||
94 | * Build Predis node configuration definition. |
||
95 | * |
||
96 | * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder |
||
97 | */ |
||
98 | private function addPredisNode() |
||
121 | |||
122 | /** |
||
123 | * Build JsonFile node configuration definition. |
||
124 | * |
||
125 | * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder |
||
126 | */ |
||
127 | private function addJsonFileNode() |
||
140 | |||
141 | /** |
||
142 | * Build dbal node configuration definition. |
||
143 | * |
||
144 | * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder |
||
145 | */ |
||
146 | private function addDbalNode() |
||
160 | |||
161 | /** |
||
162 | * Build Redis node configuration definition. |
||
163 | * |
||
164 | * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder |
||
165 | */ |
||
166 | private function addRedisNode() |
||
185 | } |
||
186 |