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