|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Patsura Dmitry https://github.com/ovr <[email protected]> |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace PHPSA; |
|
7
|
|
|
|
|
8
|
|
|
use PhpParser\ParserFactory; |
|
9
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeBuilder; |
|
10
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
11
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
12
|
|
|
use Symfony\Component\Config\Definition\Processor; |
|
13
|
|
|
|
|
14
|
|
|
class Configuration implements ConfigurationInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var array |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $configuration; |
|
20
|
|
|
|
|
21
|
379 |
|
public function __construct(array $configuration = []) |
|
22
|
|
|
{ |
|
23
|
379 |
|
$processor = new Processor(); |
|
24
|
379 |
|
$treeBuilder = $this->getConfigTreeBuilder(); |
|
25
|
|
|
|
|
26
|
379 |
|
$this->configuration = $processor->process( |
|
27
|
379 |
|
$treeBuilder->buildTree(), |
|
28
|
|
|
$configuration |
|
29
|
379 |
|
); |
|
30
|
379 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Generates the configuration tree builder. |
|
34
|
|
|
* |
|
35
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder |
|
36
|
|
|
*/ |
|
37
|
379 |
|
public function getConfigTreeBuilder() |
|
38
|
|
|
{ |
|
39
|
379 |
|
$treeBuilder = new TreeBuilder(); |
|
40
|
|
|
|
|
41
|
379 |
|
$treeBuilder->root('common', 'array', new NodeBuilder()) |
|
42
|
379 |
|
->children() |
|
43
|
379 |
|
->booleanNode('blame') |
|
44
|
379 |
|
->defaultFalse() |
|
45
|
379 |
|
->end() |
|
46
|
379 |
|
->end() |
|
47
|
379 |
|
->children() |
|
48
|
379 |
|
->enumNode('parser') |
|
49
|
379 |
|
->defaultValue('prefer-7') |
|
50
|
379 |
|
->attribute('label', 'Check types of Arguments.') |
|
51
|
379 |
|
->values( |
|
52
|
|
|
array( |
|
53
|
379 |
|
ParserFactory::PREFER_PHP7 => 'prefer-7', |
|
54
|
379 |
|
ParserFactory::PREFER_PHP5 => 'prefer-5', |
|
55
|
379 |
|
ParserFactory::ONLY_PHP7 => 'only-7', |
|
56
|
379 |
|
ParserFactory::ONLY_PHP5 => 'only-5' |
|
57
|
379 |
|
) |
|
58
|
379 |
|
); |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
379 |
|
return $treeBuilder; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function setValue($key, $value) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->configuration[$key] = $value; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param string $key |
|
71
|
|
|
* @return bool |
|
72
|
|
|
*/ |
|
73
|
6 |
|
public function valueIsTrue($key) |
|
74
|
|
|
{ |
|
75
|
6 |
|
return (bool) $this->configuration[$key]; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|