|
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
|
|
|
|
|
84
|
|
|
|
|
85
|
70 |
|
public function getId(): string |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
70 |
|
return $this->id; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
135 |
|
public function setId(string $id) |
|
|
|
|
|
|
91
|
|
|
{ |
|
92
|
135 |
|
$this->id = $id; |
|
93
|
135 |
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
|
|
|
|
|
96
|
|
|
* @return mixed |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getImportance() |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->importance; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
|
|
|
|
|
104
|
|
|
* @param mixed $importance |
|
|
|
|
|
|
105
|
|
|
*/ |
|
|
|
|
|
|
106
|
109 |
|
public function setImportance($importance) |
|
107
|
|
|
{ |
|
108
|
109 |
|
$this->importance = $importance; |
|
109
|
109 |
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
|
|
|
|
|
112
|
|
|
* @return string[] |
|
113
|
|
|
*/ |
|
114
|
52 |
|
public function getTags(): array |
|
115
|
|
|
{ |
|
116
|
52 |
|
return $this->tags; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
|
|
|
|
|
120
|
|
|
* @param string[] $tags |
|
|
|
|
|
|
121
|
|
|
*/ |
|
|
|
|
|
|
122
|
114 |
|
public function setTags(array $tags) |
|
123
|
|
|
{ |
|
124
|
114 |
|
$this->tags = $tags; |
|
125
|
114 |
|
$this->tags = array_unique($this->tags); |
|
126
|
114 |
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
|
|
|
|
|
129
|
|
|
* @param string $tag |
|
|
|
|
|
|
130
|
|
|
*/ |
|
|
|
|
|
|
131
|
|
|
public function addTag($tag) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->tags[$tag]; |
|
134
|
|
|
$this->tags = array_unique($this->tags); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
52 |
|
public function getGroup(): string |
|
|
|
|
|
|
138
|
|
|
{ |
|
139
|
52 |
|
return $this->group; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
114 |
|
public function setGroup(string $group) |
|
|
|
|
|
|
143
|
|
|
{ |
|
144
|
114 |
|
$this->group = $group; |
|
145
|
114 |
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
|
|
|
|
|
148
|
|
|
* @JMS\SerializedName("label") |
|
149
|
|
|
* @JMS\Type("string") |
|
150
|
|
|
* @JMS\VirtualProperty() |
|
151
|
|
|
* @JMS\Expose() |
|
152
|
|
|
*/ |
|
|
|
|
|
|
153
|
58 |
|
public function getLabel(): string |
|
154
|
|
|
{ |
|
155
|
58 |
|
if (null !== $this->label) { |
|
156
|
12 |
|
return $this->label; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
53 |
|
return sprintf('Check %s', $this->id); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
114 |
|
public function setLabel($label) |
|
|
|
|
|
|
163
|
|
|
{ |
|
164
|
114 |
|
$this->label = $label; |
|
165
|
114 |
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
|
|
|
|
|
168
|
|
|
* @return ?string |
|
169
|
|
|
*/ |
|
170
|
|
|
public function getDescr(): ?string |
|
171
|
|
|
{ |
|
172
|
|
|
return $this->descr; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
109 |
|
public function setDescr(?string $descr) |
|
|
|
|
|
|
176
|
|
|
{ |
|
177
|
109 |
|
$this->descr = $descr; |
|
178
|
109 |
|
} |
|
179
|
|
|
|
|
180
|
110 |
|
public function setAdditionParams(array $data) |
|
|
|
|
|
|
181
|
|
|
{ |
|
182
|
110 |
|
if (array_key_exists('id', $data)) { |
|
183
|
110 |
|
$this->setId($data['id']); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
110 |
|
if (array_key_exists('group', $data)) { |
|
187
|
110 |
|
$this->setGroup($data['group']); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
110 |
|
if (array_key_exists('importance', $data)) { |
|
191
|
109 |
|
$this->setImportance($data['importance']); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
110 |
|
if (array_key_exists('tags', $data)) { |
|
195
|
110 |
|
$this->setTags($data['tags']); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
110 |
|
if (array_key_exists('label', $data)) { |
|
199
|
110 |
|
$this->setLabel($data['label']); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
110 |
|
if (array_key_exists('descr', $data)) { |
|
203
|
109 |
|
$this->setDescr($data['descr']); |
|
204
|
|
|
} |
|
205
|
110 |
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|