|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of php-cache organization. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Cache\AdapterBundle\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
15
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
16
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class Configuration. |
|
20
|
|
|
* |
|
21
|
|
|
* @author Aaron Scherer <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class Configuration implements ConfigurationInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Generates the configuration tree builder. |
|
27
|
|
|
* |
|
28
|
|
|
* @return TreeBuilder The tree builder |
|
29
|
|
|
*/ |
|
30
|
6 |
|
public function getConfigTreeBuilder() |
|
31
|
|
|
{ |
|
32
|
|
|
|
|
33
|
6 |
|
$treeBuilder = new TreeBuilder('cache_adapter'); |
|
34
|
|
|
|
|
35
|
6 |
|
if (method_exists($treeBuilder, 'getRootNode')) { |
|
36
|
6 |
|
$rootNode = $treeBuilder->getRootNode(); |
|
37
|
|
|
} else { |
|
38
|
|
|
$rootNode = $treeBuilder->root('cache_adapter'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
6 |
|
$rootNode->children() |
|
42
|
6 |
|
->append($this->getClustersNode()) |
|
43
|
6 |
|
->end(); |
|
44
|
|
|
|
|
45
|
6 |
|
return $treeBuilder; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return ArrayNodeDefinition |
|
50
|
|
|
*/ |
|
51
|
6 |
|
private function getClustersNode() |
|
52
|
|
|
{ |
|
53
|
|
|
|
|
54
|
6 |
|
$treeBuilder = new TreeBuilder('providers'); |
|
55
|
|
|
|
|
56
|
6 |
|
if (method_exists($treeBuilder, 'getRootNode')) { |
|
57
|
6 |
|
$node = $treeBuilder->getRootNode(); |
|
58
|
|
|
} else { |
|
59
|
|
|
$node = $treeBuilder->root('providers'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$node |
|
63
|
6 |
|
->requiresAtLeastOneElement() |
|
64
|
6 |
|
->useAttributeAsKey('name') |
|
65
|
6 |
|
->prototype('array') |
|
66
|
6 |
|
->children() |
|
67
|
6 |
|
->scalarNode('factory')->isRequired()->cannotBeEmpty()->end() |
|
68
|
6 |
|
->variableNode('options')->defaultValue([])->end() |
|
69
|
6 |
|
->arrayNode('aliases') |
|
70
|
6 |
|
->prototype('scalar')->end() |
|
71
|
6 |
|
->end() |
|
72
|
6 |
|
->end() |
|
73
|
6 |
|
->end(); |
|
74
|
|
|
|
|
75
|
6 |
|
return $node; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|