1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Circles - Bring cloud-users closer together. |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the COPYING file. |
7
|
|
|
* |
8
|
|
|
* @author Maxence Lange <[email protected]> |
9
|
|
|
* @copyright 2017 |
10
|
|
|
* @license GNU AGPL version 3 or any later version |
11
|
|
|
* |
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
15
|
|
|
* License, or (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU Affero General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
24
|
|
|
* |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace OCA\Circles\Model; |
28
|
|
|
|
29
|
|
|
class Frame implements \JsonSerializable { |
30
|
|
|
|
31
|
|
|
private $source; |
32
|
|
|
private $type; |
33
|
|
|
|
34
|
|
|
/** @var int */ |
35
|
|
|
private $circleId; |
36
|
|
|
|
37
|
|
|
/** @var string */ |
38
|
|
|
private $circleName; |
39
|
|
|
|
40
|
|
|
/** @var string */ |
41
|
|
|
private $author; |
42
|
|
|
|
43
|
|
|
/** @var string */ |
44
|
|
|
private $sharer; |
45
|
|
|
|
46
|
|
|
/** @var array */ |
47
|
|
|
private $payload; |
48
|
|
|
|
49
|
|
|
/** @var int */ |
50
|
|
|
private $creation; |
51
|
|
|
|
52
|
|
|
/** @var string */ |
53
|
|
|
private $uniqueId; |
54
|
|
|
|
55
|
|
|
public function __construct(string $source, string $type) { |
56
|
|
|
$this->source = $source; |
57
|
|
|
$this->type = $type; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
public function getSource() { |
65
|
|
|
return $this->source; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function getType() { |
72
|
|
|
return $this->type; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param int $circleId |
77
|
|
|
*/ |
78
|
|
|
public function setCircleId(int $circleId) { |
79
|
|
|
$this->circleId = $circleId; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return int |
84
|
|
|
*/ |
85
|
|
|
public function getCircleId() { |
86
|
|
|
return $this->circleId; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $circleName |
92
|
|
|
*/ |
93
|
|
|
public function setCircleName(string $circleName) { |
94
|
|
|
$this->circleName = $circleName; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return mixed |
|
|
|
|
99
|
|
|
*/ |
100
|
|
|
public function getCircleName() { |
101
|
|
|
return $this->circleName; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param string $author |
107
|
|
|
*/ |
108
|
|
|
public function setAuthor(string $author) { |
109
|
|
|
$this->author = $author; |
110
|
|
|
|
111
|
|
|
if ($this->getSharer() === null) { |
112
|
|
|
$this->setSharer($author); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
|
|
public function getAuthor() { |
120
|
|
|
return $this->author; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param string $sharer |
126
|
|
|
*/ |
127
|
|
|
public function setSharer(string $sharer) { |
128
|
|
|
$this->sharer = $sharer; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
public function getSharer() { |
135
|
|
|
return $this->sharer; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param string $uniqueId |
141
|
|
|
* |
142
|
|
|
* @return Frame |
143
|
|
|
*/ |
144
|
|
|
public function setUniqueId(string $uniqueId) { |
145
|
|
|
$this->uniqueId = $uniqueId; |
146
|
|
|
|
147
|
|
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return string |
152
|
|
|
*/ |
153
|
|
|
public function getUniqueId() { |
154
|
|
|
return $this->uniqueId; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return Frame |
159
|
|
|
*/ |
160
|
|
|
public function generateUniqueId() { |
161
|
|
|
$uniqueId = bin2hex(openssl_random_pseudo_bytes(16)); |
162
|
|
|
$this->setUniqueId($uniqueId); |
163
|
|
|
|
164
|
|
|
return $this; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param array $payload |
169
|
|
|
*/ |
170
|
|
|
public function setPayload(array $payload) { |
171
|
|
|
$this->payload = $payload; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param bool $asJson |
176
|
|
|
* |
177
|
|
|
* @return array|string |
178
|
|
|
*/ |
179
|
|
|
public function getPayload(bool $asJson = false) { |
180
|
|
|
if ($asJson) { |
181
|
|
|
return json_encode($this->payload); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
return $this->payload; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param int $creation |
190
|
|
|
*/ |
191
|
|
|
public function setCreation($creation) { |
192
|
|
|
if ($creation === null) { |
193
|
|
|
return; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
$this->creation = $creation; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return int |
201
|
|
|
*/ |
202
|
|
|
public function getCreation() { |
203
|
|
|
return $this->creation; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
public function jsonSerialize() { |
208
|
|
|
return array( |
209
|
|
|
'circle_id' => $this->getCircleId(), |
210
|
|
|
'circle_name' => $this->getCircleName(), |
211
|
|
|
'source' => $this->getSource(), |
212
|
|
|
'type' => $this->getType(), |
213
|
|
|
'author' => $this->getAuthor(), |
214
|
|
|
'sharer' => $this->getSharer(), |
215
|
|
|
'payload' => $this->getPayload(), |
216
|
|
|
'creation' => $this->getCreation(), |
217
|
|
|
); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public static function fromJSON($json) { |
221
|
|
|
|
222
|
|
|
$arr = json_decode($json, true); |
223
|
|
|
|
224
|
|
|
$share = new Frame($arr['source'], $arr['type']); |
225
|
|
|
$share->setCircleId($arr['circle_id']); |
226
|
|
|
if (key_exists('circle_name', $arr)) { |
227
|
|
|
$share->setCircleName($arr['circle_name']); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
$share->setAuthor($arr['author']); |
231
|
|
|
$share->setSharer($arr['sharer']); |
232
|
|
|
$share->setPayload($arr['payload']); |
233
|
|
|
$share->setCreation($arr['creation']); |
234
|
|
|
|
235
|
|
|
return $share; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
} |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.