|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Gerard van Helden <[email protected]> |
|
4
|
|
|
* @copyright Zicht Online <http://zicht.nl> |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace Zicht\Tool\Configuration; |
|
7
|
|
|
|
|
8
|
|
|
use Zicht\Version; |
|
9
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
10
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Configuration implementation validation a Z file configuration |
|
14
|
|
|
*/ |
|
15
|
|
|
class Configuration implements ConfigurationInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var \Zicht\Tool\PluginInterface[] |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $plugins = array(); |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Construct the configuration with a set of plugins |
|
24
|
|
|
* |
|
25
|
|
|
* @param \Zicht\Tool\PluginInterface[] $plugins |
|
26
|
|
|
*/ |
|
27
|
7 |
|
public function __construct($plugins) |
|
28
|
|
|
{ |
|
29
|
7 |
|
$this->plugins = $plugins; |
|
30
|
7 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Generates the configuration tree builder. |
|
35
|
|
|
* |
|
36
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder |
|
37
|
|
|
*/ |
|
38
|
7 |
|
public function getConfigTreeBuilder() |
|
39
|
|
|
{ |
|
40
|
7 |
|
$treeBuilder = new TreeBuilder(); |
|
41
|
|
|
|
|
42
|
7 |
|
$zConfig = $treeBuilder->root('z'); |
|
43
|
|
|
$toArray = function ($s) { |
|
44
|
1 |
|
return array($s); |
|
45
|
7 |
|
}; |
|
46
|
|
|
|
|
47
|
|
|
$zConfig |
|
48
|
7 |
|
->children() |
|
49
|
7 |
|
->scalarNode('SHELL')->end() |
|
50
|
7 |
|
->scalarNode('TIMEOUT')->end() |
|
51
|
7 |
|
->arrayNode('globals') |
|
52
|
7 |
|
->defaultValue(array()) |
|
53
|
7 |
|
->prototype('variable')->end() |
|
54
|
7 |
|
->end() |
|
55
|
7 |
|
->arrayNode('tasks') |
|
56
|
7 |
|
->prototype('array') |
|
57
|
7 |
|
->beforeNormalization() |
|
58
|
7 |
|
->ifTrue( |
|
59
|
|
|
function ($in) { |
|
60
|
|
|
return |
|
61
|
1 |
|
is_string($in) |
|
62
|
|
|
|
|
63
|
|
|
// allow for 'lists' (skipping the 'do' key) |
|
64
|
1 |
|
|| (is_array($in) && range(0, count($in) - 1) === array_keys($in)); |
|
65
|
|
|
} |
|
66
|
7 |
|
) |
|
67
|
7 |
|
->then( |
|
68
|
1 |
|
function ($v) { |
|
69
|
1 |
|
return array('do' => $v); |
|
70
|
|
|
} |
|
71
|
7 |
|
) |
|
72
|
7 |
|
->end() |
|
73
|
7 |
|
->children() |
|
74
|
7 |
|
->scalarNode('name')->end() |
|
75
|
7 |
|
->scalarNode('help')->defaultValue(null)->end() |
|
76
|
7 |
|
->arrayNode('flags') |
|
77
|
7 |
|
->prototype('boolean')->end() |
|
78
|
7 |
|
->useAttributeAsKey('name') |
|
79
|
7 |
|
->defaultValue(array()) |
|
80
|
7 |
|
->end() |
|
81
|
7 |
|
->arrayNode('opts') |
|
82
|
7 |
|
->prototype('scalar')->end() |
|
83
|
7 |
|
->useAttributeAsKey('name') |
|
84
|
7 |
|
->defaultValue(array()) |
|
85
|
7 |
|
->end() |
|
86
|
7 |
|
->arrayNode('args') |
|
87
|
7 |
|
->prototype('scalar')->end() |
|
88
|
7 |
|
->useAttributeAsKey('name') |
|
89
|
7 |
|
->defaultValue(array()) |
|
90
|
7 |
|
->end() |
|
91
|
7 |
|
->arrayNode('set') |
|
92
|
7 |
|
->prototype('scalar')->end() |
|
93
|
7 |
|
->useAttributeAsKey('name') |
|
94
|
7 |
|
->defaultValue(array()) |
|
95
|
7 |
|
->end() |
|
96
|
7 |
|
->scalarNode('unless')->defaultValue(null)->end() |
|
97
|
7 |
|
->scalarNode('if')->defaultValue(null)->end() |
|
98
|
7 |
|
->scalarNode('assert')->defaultValue(null)->end() |
|
99
|
7 |
|
->arrayNode('pre') |
|
100
|
7 |
|
->beforeNormalization() |
|
101
|
7 |
|
->ifString()->then($toArray) |
|
102
|
7 |
|
->end() |
|
103
|
7 |
|
->prototype('scalar')->end() |
|
104
|
7 |
|
->defaultValue(array()) |
|
105
|
7 |
|
->end() |
|
106
|
7 |
|
->arrayNode('post') |
|
107
|
7 |
|
->beforeNormalization() |
|
108
|
7 |
|
->ifString()->then($toArray) |
|
109
|
7 |
|
->end() |
|
110
|
7 |
|
->prototype('scalar')->end() |
|
111
|
7 |
|
->defaultValue(array()) |
|
112
|
7 |
|
->end() |
|
113
|
7 |
|
->arrayNode('do') |
|
114
|
7 |
|
->beforeNormalization() |
|
115
|
7 |
|
->ifString()->then($toArray) |
|
116
|
7 |
|
->end() |
|
117
|
7 |
|
->performNoDeepMerging() |
|
118
|
7 |
|
->prototype('scalar')->end() |
|
119
|
7 |
|
->defaultValue(array()) |
|
120
|
7 |
|
->end() |
|
121
|
7 |
|
->scalarNode('yield')->defaultValue(null)->end() |
|
122
|
7 |
|
->end() |
|
123
|
7 |
|
->end() |
|
124
|
7 |
|
->useAttributeAsKey('name') |
|
125
|
7 |
|
->end() |
|
126
|
7 |
|
->end() |
|
127
|
7 |
|
->end(); |
|
128
|
|
|
|
|
129
|
7 |
|
foreach ($this->plugins as $plugin) { |
|
130
|
2 |
|
$plugin->appendConfiguration($zConfig); |
|
131
|
7 |
|
} |
|
132
|
|
|
|
|
133
|
7 |
|
return $treeBuilder; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|