|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Circles - Bring cloud-users closer together. |
|
6
|
|
|
* |
|
7
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
8
|
|
|
* later. See the COPYING file. |
|
9
|
|
|
* |
|
10
|
|
|
* @author Maxence Lange <[email protected]> |
|
11
|
|
|
* @copyright 2017 |
|
12
|
|
|
* @license GNU AGPL version 3 or any later version |
|
13
|
|
|
* |
|
14
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
15
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
16
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
17
|
|
|
* License, or (at your option) any later version. |
|
18
|
|
|
* |
|
19
|
|
|
* This program is distributed in the hope that it will be useful, |
|
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
* GNU Affero General Public License for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
25
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
namespace OCA\Circles\Model\GlobalScale; |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
use daita\MySmallPhpTools\Traits\TArrayTools; |
|
34
|
|
|
use JsonSerializable; |
|
35
|
|
|
use OCA\Circles\Exceptions\JsonException; |
|
36
|
|
|
use OCA\Circles\Exceptions\ModelException; |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Class GSEvent |
|
41
|
|
|
* |
|
42
|
|
|
* @package OCA\Circles\Model\GlobalScale |
|
43
|
|
|
*/ |
|
44
|
|
|
class GSWrapper implements JsonSerializable { |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
use TArrayTools; |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
const STATUS_INIT = 0; |
|
51
|
|
|
const STATUS_FAILED = 1; |
|
52
|
|
|
const STATUS_DONE = 8; |
|
53
|
|
|
const STATUS_OVER = 9; |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
/** @var string */ |
|
57
|
|
|
private $token = ''; |
|
58
|
|
|
|
|
59
|
|
|
/** @var GSEvent */ |
|
60
|
|
|
private $event; |
|
61
|
|
|
|
|
62
|
|
|
/** @var string */ |
|
63
|
|
|
private $instance = ''; |
|
64
|
|
|
|
|
65
|
|
|
/** @var int */ |
|
66
|
|
|
private $severity = GSEvent::SEVERITY_LOW; |
|
67
|
|
|
|
|
68
|
|
|
/** @var int */ |
|
69
|
|
|
private $status = 0; |
|
70
|
|
|
|
|
71
|
|
|
/** @var int */ |
|
72
|
|
|
private $creation; |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
function __construct() { |
|
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getToken(): string { |
|
83
|
|
|
return $this->token; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param string $token |
|
88
|
|
|
* |
|
89
|
|
|
* @return GSWrapper |
|
90
|
|
|
*/ |
|
91
|
|
|
public function setToken(string $token): self { |
|
92
|
|
|
$this->token = $token; |
|
93
|
|
|
|
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return GSEvent |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getEvent(): GSEvent { |
|
102
|
|
|
return $this->event; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param GSEvent $event |
|
107
|
|
|
* |
|
108
|
|
|
* @return GSWrapper |
|
109
|
|
|
*/ |
|
110
|
|
|
public function setEvent(GSEvent $event): self { |
|
111
|
|
|
$this->event = $event; |
|
112
|
|
|
|
|
113
|
|
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return bool |
|
118
|
|
|
*/ |
|
119
|
|
|
public function hasEvent(): bool { |
|
120
|
|
|
return ($this->event !== null); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @return string |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getInstance(): string { |
|
128
|
|
|
return $this->instance; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @param string $instance |
|
133
|
|
|
* |
|
134
|
|
|
* @return GSWrapper |
|
135
|
|
|
*/ |
|
136
|
|
|
public function setInstance(string $instance): self { |
|
137
|
|
|
$this->instance = $instance; |
|
138
|
|
|
|
|
139
|
|
|
return $this; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @return int |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getSeverity(): int { |
|
147
|
|
|
return $this->severity; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @param int $severity |
|
152
|
|
|
* |
|
153
|
|
|
* @return GSWrapper |
|
154
|
|
|
*/ |
|
155
|
|
|
public function setSeverity(int $severity): self { |
|
156
|
|
|
$this->severity = $severity; |
|
157
|
|
|
|
|
158
|
|
|
return $this; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @return int |
|
164
|
|
|
*/ |
|
165
|
|
|
public function getStatus(): int { |
|
166
|
|
|
return $this->status; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @param int $status |
|
171
|
|
|
* |
|
172
|
|
|
* @return GSWrapper |
|
173
|
|
|
*/ |
|
174
|
|
|
public function setStatus(int $status): self { |
|
175
|
|
|
$this->status = $status; |
|
176
|
|
|
|
|
177
|
|
|
return $this; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* @return int |
|
183
|
|
|
*/ |
|
184
|
|
|
public function getCreation(): int { |
|
185
|
|
|
return $this->creation; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* @param int $creation |
|
190
|
|
|
* |
|
191
|
|
|
* @return GSWrapper |
|
192
|
|
|
*/ |
|
193
|
|
|
public function setCreation(int $creation): self { |
|
194
|
|
|
$this->creation = $creation; |
|
195
|
|
|
|
|
196
|
|
|
return $this; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @param array $data |
|
202
|
|
|
* |
|
203
|
|
|
* @return GSWrapper |
|
204
|
|
|
* @throws JsonException |
|
205
|
|
|
* @throws ModelException |
|
206
|
|
|
*/ |
|
207
|
|
|
public function import(array $data): self { |
|
208
|
|
|
$this->setToken($this->get('token', $data)); |
|
209
|
|
|
$this->setInstance($this->get('instance', $data)); |
|
210
|
|
|
$this->setSeverity($this->getInt('severity', $data, GSEvent::SEVERITY_LOW)); |
|
211
|
|
|
$this->setStatus($this->getInt('status', $data, GSWrapper::STATUS_INIT)); |
|
212
|
|
|
|
|
213
|
|
|
$event = new GSEvent(); |
|
214
|
|
|
$event->importFromJson($this->get('event', $data)); |
|
215
|
|
|
|
|
216
|
|
|
$this->setEvent($event); |
|
217
|
|
|
|
|
218
|
|
|
$this->setCreation($this->getInt('creation', $data)); |
|
219
|
|
|
|
|
220
|
|
|
return $this; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* @return array |
|
226
|
|
|
*/ |
|
227
|
|
|
function jsonSerialize(): array { |
|
|
|
|
|
|
228
|
|
|
$arr = [ |
|
229
|
|
|
'id' => $this->getToken(), |
|
230
|
|
|
'event' => $this->getEvent(), |
|
231
|
|
|
'severity' => $this->getSeverity(), |
|
232
|
|
|
'status' => $this->getStatus(), |
|
233
|
|
|
'creation' => $this->getCreation() |
|
234
|
|
|
]; |
|
235
|
|
|
|
|
236
|
|
|
$this->cleanArray($arr); |
|
237
|
|
|
|
|
238
|
|
|
return $arr; |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.