|
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 JMS\Serializer\Annotation as JMS; |
|
15
|
|
|
use ZendDiagnostics\Result\ResultInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
|
|
|
|
|
18
|
|
|
* @author Vladimir Turnaev <[email protected]> |
|
19
|
|
|
*/ |
|
|
|
|
|
|
20
|
|
|
trait CheckTrait |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
|
|
|
|
|
23
|
|
|
* @JMS\SerializedName("id") |
|
24
|
|
|
* @JMS\Expose() |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $id; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
|
|
|
|
|
31
|
|
|
* @var ?string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $label; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
|
|
|
|
|
36
|
|
|
* @JMS\SerializedName("group") |
|
37
|
|
|
* @JMS\Type("string") |
|
38
|
|
|
* @JMS\Expose() |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $group; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
|
|
|
|
|
45
|
|
|
* @JMS\SerializedName("descr") |
|
46
|
|
|
* @JMS\Type("string") |
|
47
|
|
|
* @JMS\SkipWhenEmpty() |
|
48
|
|
|
* @JMS\Expose() |
|
49
|
|
|
* |
|
50
|
|
|
* @var string? |
|
|
|
|
|
|
51
|
|
|
*/ |
|
52
|
|
|
protected $descr; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
|
|
|
|
|
55
|
|
|
* @JMS\SerializedName("importance") |
|
56
|
|
|
* @JMS\SkipWhenEmpty() |
|
57
|
|
|
* @JMS\Type("string") |
|
58
|
|
|
* @JMS\Expose() |
|
59
|
|
|
* |
|
60
|
|
|
* @var ?string |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $importance; |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
/** |
|
|
|
|
|
|
67
|
|
|
* @JMS\SerializedName("tags") |
|
68
|
|
|
* @JMS\SkipWhenEmpty() |
|
69
|
|
|
* @JMS\Type("array<string>") |
|
70
|
|
|
* @JMS\Expose() |
|
71
|
|
|
* |
|
72
|
|
|
* @var string[] |
|
73
|
|
|
*/ |
|
74
|
|
|
protected $tags = []; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Perform the actual check and return a ResultInterface. |
|
78
|
|
|
* |
|
79
|
|
|
* @return ResultInterface |
|
80
|
|
|
*/ |
|
81
|
|
|
abstract public function check(); |
|
82
|
|
|
|
|
83
|
71 |
|
public function getId(): string |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
71 |
|
return $this->id; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
136 |
|
public function setId(string $id) |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
136 |
|
$this->id = $id; |
|
91
|
136 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
47 |
|
public function getImportance() |
|
|
|
|
|
|
95
|
|
|
{ |
|
96
|
47 |
|
return $this->importance; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
110 |
|
public function setImportance($importance) |
|
|
|
|
|
|
101
|
|
|
{ |
|
102
|
110 |
|
$this->importance = $importance; |
|
103
|
110 |
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
|
|
|
|
|
106
|
|
|
* @return string[] |
|
107
|
|
|
*/ |
|
108
|
53 |
|
public function getTags(): array |
|
109
|
|
|
{ |
|
110
|
53 |
|
return $this->tags; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
|
|
|
|
|
114
|
|
|
* @param string[] $tags |
|
|
|
|
|
|
115
|
|
|
*/ |
|
|
|
|
|
|
116
|
115 |
|
public function setTags(array $tags) |
|
117
|
|
|
{ |
|
118
|
115 |
|
$this->tags = $tags; |
|
119
|
115 |
|
$this->tags = array_unique($this->tags); |
|
120
|
115 |
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
|
|
|
|
|
123
|
|
|
* @param string $tag |
|
|
|
|
|
|
124
|
|
|
*/ |
|
|
|
|
|
|
125
|
|
|
public function addTag($tag) |
|
126
|
|
|
{ |
|
127
|
|
|
$this->tags[$tag]; |
|
128
|
|
|
$this->tags = array_unique($this->tags); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
53 |
|
public function getGroup(): string |
|
|
|
|
|
|
132
|
|
|
{ |
|
133
|
53 |
|
return $this->group; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
115 |
|
public function setGroup(string $group) |
|
|
|
|
|
|
137
|
|
|
{ |
|
138
|
115 |
|
$this->group = $group; |
|
139
|
115 |
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
|
|
|
|
|
142
|
|
|
* @JMS\SerializedName("label") |
|
143
|
|
|
* @JMS\Type("string") |
|
144
|
|
|
* @JMS\VirtualProperty() |
|
145
|
|
|
* @JMS\Expose() |
|
146
|
|
|
*/ |
|
|
|
|
|
|
147
|
59 |
|
public function getLabel(): string |
|
148
|
|
|
{ |
|
149
|
59 |
|
if (null !== $this->label) { |
|
150
|
13 |
|
return $this->label; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
54 |
|
return sprintf('Check %s', $this->id); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
115 |
|
public function setLabel($label) |
|
|
|
|
|
|
157
|
|
|
{ |
|
158
|
115 |
|
$this->label = $label; |
|
159
|
115 |
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
|
|
|
|
|
162
|
|
|
* @return ?string |
|
163
|
|
|
*/ |
|
164
|
|
|
public function getDescr(): ?string |
|
165
|
|
|
{ |
|
166
|
|
|
return $this->descr; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
110 |
|
public function setDescr(?string $descr) |
|
|
|
|
|
|
170
|
|
|
{ |
|
171
|
110 |
|
$this->descr = $descr; |
|
172
|
110 |
|
} |
|
173
|
|
|
|
|
174
|
111 |
|
public function setAdditionParams(array $data) |
|
|
|
|
|
|
175
|
|
|
{ |
|
176
|
111 |
|
if (array_key_exists('id', $data)) { |
|
177
|
111 |
|
$this->setId($data['id']); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
111 |
|
if (array_key_exists('group', $data)) { |
|
181
|
111 |
|
$this->setGroup($data['group']); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
111 |
|
if (array_key_exists('importance', $data)) { |
|
185
|
110 |
|
$this->setImportance($data['importance']); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
111 |
|
if (array_key_exists('tags', $data)) { |
|
189
|
111 |
|
$this->setTags($data['tags']); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
111 |
|
if (array_key_exists('label', $data)) { |
|
193
|
111 |
|
$this->setLabel($data['label']); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
111 |
|
if (array_key_exists('descr', $data)) { |
|
197
|
110 |
|
$this->setDescr($data['descr']); |
|
198
|
|
|
} |
|
199
|
111 |
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|