|
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
|
|
|
|
|
16
|
|
|
/** |
|
|
|
|
|
|
17
|
|
|
* @JMS\AccessorOrder("custom", custom = {"id", "name", "label", "descr", "count"}) |
|
18
|
|
|
* @JMS\VirtualProperty( |
|
19
|
|
|
* exp="object.count()", |
|
20
|
|
|
* options={@JMS\SerializedName("count")} |
|
21
|
|
|
* ) |
|
22
|
|
|
* |
|
23
|
|
|
* @author Vladimir Turnaev <[email protected]> |
|
24
|
|
|
*/ |
|
|
|
|
|
|
25
|
|
|
class Group implements \ArrayAccess, \Iterator, \Countable |
|
26
|
|
|
{ |
|
27
|
|
|
use CheckArraybleTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
|
|
|
|
|
30
|
|
|
* @JMS\Exclude() |
|
31
|
|
|
* |
|
32
|
|
|
* @var CheckInterface[] |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $checks = []; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
|
|
|
|
|
37
|
|
|
* @JMS\SerializedName("id") |
|
38
|
|
|
* @JMS\Type("string") |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $id; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
|
|
|
|
|
45
|
|
|
* @JMS\SerializedName("name") |
|
46
|
|
|
* @JMS\Type("string") |
|
47
|
|
|
* |
|
48
|
|
|
* @var string |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $name; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
|
|
|
|
|
53
|
|
|
* @JMS\SerializedName("descr") |
|
54
|
|
|
* @JMS\Type("string") |
|
55
|
|
|
* @JMS\SkipWhenEmpty() |
|
56
|
|
|
* |
|
57
|
|
|
* @var ?string |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $descr; |
|
60
|
|
|
|
|
61
|
97 |
|
public function __construct(string $id, ?string $name = null, ?string $descr = null) |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
97 |
|
$this->id = $id; |
|
64
|
97 |
|
$this->name = null === $name ? $id : $name; |
|
65
|
97 |
|
$this->descr = $descr; |
|
66
|
97 |
|
} |
|
67
|
|
|
|
|
68
|
84 |
|
public function getId(): string |
|
|
|
|
|
|
69
|
|
|
{ |
|
70
|
84 |
|
return $this->id; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
|
|
|
|
|
74
|
|
|
* @param mixed $name |
|
|
|
|
|
|
75
|
|
|
* |
|
76
|
|
|
* @return $this |
|
77
|
|
|
*/ |
|
78
|
1 |
|
public function setName(string $name): self |
|
79
|
|
|
{ |
|
80
|
1 |
|
$this->name = $name; |
|
81
|
|
|
|
|
82
|
1 |
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
84 |
|
public function getName(): string |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
84 |
|
return $this->name; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
|
|
|
|
|
91
|
|
|
* @param mixed $descr |
|
|
|
|
|
|
92
|
|
|
* |
|
93
|
|
|
* @return $this |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function setDescr(?string $descr): self |
|
96
|
|
|
{ |
|
97
|
1 |
|
$this->descr = $descr; |
|
98
|
|
|
|
|
99
|
1 |
|
return $this; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
1 |
|
public function getDescr(): ?string |
|
|
|
|
|
|
103
|
|
|
{ |
|
104
|
1 |
|
return $this->descr; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
|
|
|
|
|
108
|
|
|
* @param CheckInterface|Proxy $check |
|
|
|
|
|
|
109
|
|
|
* |
|
110
|
|
|
* @return $this |
|
111
|
|
|
*/ |
|
112
|
97 |
|
public function addCheck(string $checkId, &$check): self |
|
113
|
|
|
{ |
|
114
|
97 |
|
$this->checks[$checkId] = &$check; |
|
115
|
|
|
|
|
116
|
97 |
|
return $this; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
|
|
|
|
|
120
|
|
|
* @JMS\SerializedName("label") |
|
121
|
|
|
* @JMS\Type("string") |
|
122
|
|
|
* @JMS\VirtualProperty() |
|
123
|
|
|
* |
|
124
|
|
|
* @return string |
|
125
|
|
|
*/ |
|
126
|
2 |
|
public function getLabel() |
|
127
|
|
|
{ |
|
128
|
2 |
|
return sprintf('%s(%d)', $this->name, $this->count()); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
|
|
|
|
|
132
|
|
|
* @JMS\SerializedName("checks") |
|
133
|
|
|
* @JMS\SkipWhenEmpty() |
|
134
|
|
|
* @JMS\Type("array<string>") |
|
135
|
|
|
* @JMS\VirtualProperty() |
|
136
|
|
|
* |
|
137
|
|
|
* @return string[] |
|
138
|
|
|
*/ |
|
139
|
3 |
|
public function getCheckIds(): array |
|
140
|
|
|
{ |
|
141
|
3 |
|
return array_keys($this->checks); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|