1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace YamlStandards\Model\Config; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
8
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
9
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
10
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
11
|
|
|
|
12
|
|
|
class YamlStandardConfigDefinition implements ConfigurationInterface |
13
|
|
|
{ |
14
|
|
|
public const CONFIG_PATHS_TO_CHECK = 'pathsToCheck'; |
15
|
|
|
public const CONFIG_EXCLUDED_PATHS = 'excludedPaths'; |
16
|
|
|
public const CONFIG_CHECKERS = 'checkers'; |
17
|
|
|
public const CONFIG_PATH_TO_CHECKER = 'pathToChecker'; |
18
|
|
|
public const CONFIG_PARAMETERS_FOR_CHECKER = 'parameters'; |
19
|
|
|
public const CONFIG_PARAMETERS_DEPTH = 'depth'; |
20
|
|
|
public const CONFIG_PARAMETERS_INDENTS = 'indents'; |
21
|
|
|
public const CONFIG_PARAMETERS_LEVEL = 'level'; |
22
|
|
|
public const CONFIG_PARAMETERS_SERVICE_ALIASING_TYPE = 'serviceAliasingType'; |
23
|
|
|
|
24
|
|
|
public const CONFIG_PARAMETERS_SERVICE_ALIASING_TYPE_VALUE_SHORT = 'short'; |
25
|
|
|
public const CONFIG_PARAMETERS_SERVICE_ALIASING_TYPE_VALUE_LONG = 'long'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @inheritDoc |
29
|
|
|
*/ |
30
|
9 |
|
public function getConfigTreeBuilder(): TreeBuilder |
31
|
|
|
{ |
32
|
|
|
// fix for Symfony 4.2 and newer versions |
33
|
9 |
|
if (Kernel::VERSION_ID >= 40200) { |
34
|
9 |
|
$treeBuilder = new TreeBuilder('yaml_standards_config'); |
35
|
|
|
/** @var \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $rootNode */ |
36
|
9 |
|
$rootNode = $treeBuilder->getRootNode(); |
37
|
|
|
} else { |
38
|
|
|
$treeBuilder = new TreeBuilder(); |
39
|
|
|
/** @var \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $rootNode */ |
40
|
|
|
$rootNode = $treeBuilder->root('yaml_standards_config'); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
9 |
|
$this->buildItemsNode($rootNode->arrayPrototype()); |
44
|
|
|
|
45
|
9 |
|
return $treeBuilder; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node |
50
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition |
51
|
|
|
*/ |
52
|
9 |
|
private function buildItemsNode(ArrayNodeDefinition $node): ArrayNodeDefinition |
53
|
|
|
{ |
54
|
|
|
return $node |
55
|
9 |
|
->children() |
56
|
9 |
|
->arrayNode(self::CONFIG_PATHS_TO_CHECK)->isRequired()->cannotBeEmpty() |
57
|
9 |
|
->prototype('scalar')->end() |
58
|
9 |
|
->end() |
|
|
|
|
59
|
9 |
|
->arrayNode(self::CONFIG_EXCLUDED_PATHS) |
60
|
9 |
|
->prototype('scalar')->end() |
61
|
9 |
|
->end() |
62
|
9 |
|
->arrayNode(self::CONFIG_CHECKERS) |
63
|
9 |
|
->isRequired() |
64
|
9 |
|
->arrayPrototype() |
65
|
9 |
|
->children() |
66
|
9 |
|
->scalarNode(self::CONFIG_PATH_TO_CHECKER)->defaultNull()->end() |
67
|
9 |
|
->arrayNode(self::CONFIG_PARAMETERS_FOR_CHECKER) |
68
|
9 |
|
->addDefaultsIfNotSet() |
69
|
9 |
|
->children() |
70
|
9 |
|
->scalarNode(self::CONFIG_PARAMETERS_DEPTH)->defaultNull()->end() |
71
|
9 |
|
->scalarNode(self::CONFIG_PARAMETERS_INDENTS)->defaultNull()->end() |
72
|
9 |
|
->scalarNode(self::CONFIG_PARAMETERS_LEVEL)->defaultNull()->end() |
73
|
9 |
|
->enumNode(self::CONFIG_PARAMETERS_SERVICE_ALIASING_TYPE)->defaultNull()->values([ |
74
|
9 |
|
self::CONFIG_PARAMETERS_SERVICE_ALIASING_TYPE_VALUE_SHORT, |
75
|
9 |
|
self::CONFIG_PARAMETERS_SERVICE_ALIASING_TYPE_VALUE_LONG, |
76
|
9 |
|
])->end() |
77
|
9 |
|
->end() |
78
|
9 |
|
->end() |
79
|
9 |
|
->end() |
80
|
9 |
|
->end() |
81
|
9 |
|
->end() |
82
|
9 |
|
->end() |
83
|
9 |
|
->end(); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.