|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the `tvi/monitor-bundle` project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) https://github.com/turnaev/monitor-bundle/graphs/contributors |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Tvi\MonitorBundle\Check; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
15
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
16
|
|
|
use Tvi\MonitorBundle\Exception\FeatureRequired; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
|
|
|
|
|
19
|
|
|
* @author Vladimir Turnaev <[email protected]> |
|
20
|
|
|
*/ |
|
|
|
|
|
|
21
|
|
|
abstract class CheckPluginAbstract implements CheckPluginInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
|
|
|
|
|
24
|
|
|
* @throws FeatureRequired |
|
25
|
|
|
*/ |
|
|
|
|
|
|
26
|
35 |
|
public function checkRequirements(array $checkSettings) |
|
27
|
|
|
{ |
|
28
|
35 |
|
} |
|
29
|
|
|
|
|
30
|
57 |
|
public function checkConf(TreeBuilder $builder): ArrayNodeDefinition |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
$node = $builder |
|
33
|
57 |
|
->root(static::CHECK_NAME, 'array') |
|
34
|
57 |
|
->info(static::DESCR); //-- |
|
35
|
|
|
|
|
36
|
57 |
|
$this->_check($node); |
|
37
|
|
|
|
|
38
|
57 |
|
return $node; |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
57 |
|
public function checkFactoryConf(TreeBuilder $builder): ArrayNodeDefinition |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
|
|
$node = $builder |
|
44
|
57 |
|
->root(static::CHECK_NAME.'_factory', 'array') |
|
45
|
57 |
|
->info(static::DESCR) |
|
46
|
57 |
|
->children() |
|
47
|
57 |
|
->arrayNode('items') |
|
|
|
|
|
|
48
|
57 |
|
->prototype('array'); //-- |
|
|
|
|
|
|
49
|
57 |
|
$node = $this->_check($node) |
|
50
|
57 |
|
->end() |
|
|
|
|
|
|
51
|
57 |
|
->end() |
|
|
|
|
|
|
52
|
57 |
|
->end(); |
|
53
|
|
|
|
|
54
|
57 |
|
$this->_addition($node); |
|
55
|
|
|
|
|
56
|
57 |
|
return $node; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
57 |
|
protected function _addition(ArrayNodeDefinition $node): ArrayNodeDefinition |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
57 |
|
$this->_group($node); |
|
62
|
57 |
|
$this->_tags($node); |
|
63
|
57 |
|
$this->_importance($node); |
|
64
|
57 |
|
$this->_label($node); |
|
65
|
57 |
|
$this->_descr($node); |
|
66
|
|
|
|
|
67
|
57 |
|
return $node; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
abstract protected function _check(ArrayNodeDefinition $node): ArrayNodeDefinition; |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
57 |
|
protected function _label(ArrayNodeDefinition $node): ArrayNodeDefinition |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
|
|
return $node |
|
75
|
57 |
|
->children() |
|
76
|
57 |
|
->scalarNode('label')->defaultNull()->end() |
|
|
|
|
|
|
77
|
57 |
|
->end(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
57 |
|
protected function _importance(ArrayNodeDefinition $node): ArrayNodeDefinition |
|
|
|
|
|
|
81
|
|
|
{ |
|
82
|
|
|
return $node |
|
83
|
57 |
|
->children() |
|
84
|
57 |
|
->scalarNode('importance') |
|
|
|
|
|
|
85
|
57 |
|
->validate() |
|
|
|
|
|
|
86
|
57 |
|
->ifTrue(static function ($value) { |
|
|
|
|
|
|
87
|
1 |
|
if (null === $value) { |
|
88
|
|
|
return false; |
|
89
|
1 |
|
} elseif (\in_array($value, CheckAbstract::getImportances(), true)) { |
|
90
|
1 |
|
return false; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return true; |
|
94
|
57 |
|
}) |
|
|
|
|
|
|
95
|
57 |
|
->thenInvalid(sprintf('importance has to one of value [%s]', implode(', ', CheckAbstract::getImportances()))) |
|
96
|
57 |
|
->end() |
|
97
|
57 |
|
->defaultNull() |
|
98
|
57 |
|
->end() |
|
99
|
57 |
|
->end(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
57 |
|
protected function _group(ArrayNodeDefinition $node): ArrayNodeDefinition |
|
|
|
|
|
|
103
|
|
|
{ |
|
104
|
|
|
return $node |
|
105
|
57 |
|
->children() |
|
106
|
57 |
|
->scalarNode('group') |
|
|
|
|
|
|
107
|
57 |
|
->cannotBeEmpty() |
|
|
|
|
|
|
108
|
57 |
|
->end() |
|
|
|
|
|
|
109
|
57 |
|
->scalarNode('_group') |
|
|
|
|
|
|
110
|
57 |
|
->defaultValue(static::GROUP) |
|
|
|
|
|
|
111
|
57 |
|
->cannotBeOverwritten() |
|
|
|
|
|
|
112
|
57 |
|
->end() |
|
|
|
|
|
|
113
|
57 |
|
->end(); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
57 |
|
protected function _tags(ArrayNodeDefinition $node): ArrayNodeDefinition |
|
|
|
|
|
|
117
|
|
|
{ |
|
118
|
|
|
return $node |
|
119
|
57 |
|
->children() |
|
120
|
57 |
|
->arrayNode('tags') |
|
|
|
|
|
|
121
|
57 |
|
->prototype('scalar')->end() |
|
|
|
|
|
|
122
|
57 |
|
->end() |
|
|
|
|
|
|
123
|
57 |
|
->end(); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
57 |
|
protected function _descr(ArrayNodeDefinition $node): ArrayNodeDefinition |
|
|
|
|
|
|
127
|
|
|
{ |
|
128
|
|
|
return $node |
|
129
|
57 |
|
->children() |
|
130
|
57 |
|
->scalarNode('descr') |
|
|
|
|
|
|
131
|
57 |
|
->defaultNull() |
|
|
|
|
|
|
132
|
57 |
|
->end() |
|
|
|
|
|
|
133
|
57 |
|
->end(); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|