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("tags") |
56
|
|
|
* @JMS\SkipWhenEmpty() |
57
|
|
|
* @JMS\Type("array<string>") |
58
|
|
|
* @JMS\Expose() |
59
|
|
|
* |
60
|
|
|
* @var string[] |
61
|
|
|
*/ |
62
|
|
|
protected $tags = []; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Perform the actual check and return a ResultInterface. |
66
|
|
|
* |
67
|
|
|
* @return ResultInterface |
68
|
|
|
*/ |
69
|
|
|
abstract public function check(); |
70
|
|
|
|
71
|
62 |
|
public function getId(): string |
|
|
|
|
72
|
|
|
{ |
73
|
62 |
|
return $this->id; |
74
|
|
|
} |
75
|
|
|
|
76
|
123 |
|
public function setId(string $id): self |
|
|
|
|
77
|
|
|
{ |
78
|
123 |
|
$this->id = $id; |
79
|
|
|
|
80
|
123 |
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
|
|
|
|
84
|
|
|
* @return string[] |
85
|
|
|
*/ |
86
|
51 |
|
public function getTags(): array |
87
|
|
|
{ |
88
|
51 |
|
return $this->tags; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
|
|
|
|
92
|
|
|
* @param string[] $tags |
|
|
|
|
93
|
|
|
*/ |
|
|
|
|
94
|
102 |
|
public function setTags(array $tags): self |
95
|
|
|
{ |
96
|
102 |
|
$this->tags = $tags; |
97
|
|
|
|
98
|
102 |
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
51 |
|
public function getGroup(): string |
|
|
|
|
102
|
|
|
{ |
103
|
51 |
|
return $this->group; |
104
|
|
|
} |
105
|
|
|
|
106
|
102 |
|
public function setGroup(string $group): self |
|
|
|
|
107
|
|
|
{ |
108
|
102 |
|
$this->group = $group; |
109
|
|
|
|
110
|
102 |
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
|
|
|
|
114
|
|
|
* @JMS\SerializedName("label") |
115
|
|
|
* @JMS\Type("string") |
116
|
|
|
* @JMS\VirtualProperty() |
117
|
|
|
* @JMS\Expose() |
118
|
|
|
*/ |
|
|
|
|
119
|
48 |
|
public function getLabel(): string |
120
|
|
|
{ |
121
|
48 |
|
if (null !== $this->label) { |
122
|
9 |
|
return $this->label; |
123
|
|
|
} |
124
|
|
|
|
125
|
43 |
|
return sprintf('Check %s', $this->id); |
126
|
|
|
} |
127
|
|
|
|
128
|
102 |
|
public function setLabel($label): self |
|
|
|
|
129
|
|
|
{ |
130
|
102 |
|
$this->label = $label; |
131
|
|
|
|
132
|
102 |
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
|
|
|
|
136
|
|
|
* @return ?string |
137
|
|
|
*/ |
138
|
|
|
public function getDescr(): ?string |
139
|
|
|
{ |
140
|
|
|
return $this->descr; |
141
|
|
|
} |
142
|
|
|
|
143
|
97 |
|
public function setDescr(?string $descr): self |
|
|
|
|
144
|
|
|
{ |
145
|
97 |
|
$this->descr = $descr; |
146
|
|
|
|
147
|
97 |
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
98 |
|
public function setAdditionParams(array $data): self |
|
|
|
|
151
|
|
|
{ |
152
|
98 |
|
if (array_key_exists('id', $data)) { |
153
|
98 |
|
$this->setId($data['id']); |
154
|
|
|
} |
155
|
|
|
|
156
|
98 |
|
if (array_key_exists('group', $data)) { |
157
|
98 |
|
$this->setGroup($data['group']); |
158
|
|
|
} |
159
|
|
|
|
160
|
98 |
|
if (array_key_exists('tags', $data)) { |
161
|
98 |
|
$this->setTags($data['tags']); |
162
|
|
|
} |
163
|
|
|
|
164
|
98 |
|
if (array_key_exists('label', $data)) { |
165
|
98 |
|
$this->setLabel($data['label']); |
166
|
|
|
} |
167
|
|
|
|
168
|
98 |
|
if (array_key_exists('descr', $data)) { |
169
|
97 |
|
$this->setDescr($data['descr']); |
170
|
|
|
} |
171
|
|
|
|
172
|
98 |
|
return $this; |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|