1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Chabok; |
4
|
|
|
|
5
|
|
|
class ChabokMessage |
6
|
|
|
{ |
7
|
|
|
/** @var string */ |
8
|
|
|
protected $user; |
9
|
|
|
|
10
|
|
|
/** @var string */ |
11
|
|
|
protected $content; |
12
|
|
|
|
13
|
|
|
/** @var array*/ |
14
|
|
|
protected $data = []; |
15
|
|
|
|
16
|
|
|
/** @var string */ |
17
|
|
|
protected $trackId; |
18
|
|
|
|
19
|
|
|
/** @var boolean */ |
20
|
|
|
protected $inApp = false; |
21
|
|
|
|
22
|
|
|
/** @var boolean */ |
23
|
|
|
protected $live = false; |
24
|
|
|
|
25
|
|
|
/** @var boolean */ |
26
|
|
|
protected $useAsAlert = false; |
27
|
|
|
|
28
|
|
|
/** @var string */ |
29
|
|
|
protected $alertText; |
30
|
|
|
|
31
|
|
|
/** @var integer */ |
32
|
|
|
protected $ttl; |
33
|
|
|
|
34
|
|
|
/** @var array*/ |
35
|
|
|
protected $fallback = []; |
36
|
|
|
|
37
|
|
|
/** @var string */ |
38
|
|
|
protected $clientId; |
39
|
|
|
|
40
|
|
|
/** @var array*/ |
41
|
|
|
protected $notification = []; |
42
|
|
|
|
43
|
|
|
/** @var boolean */ |
44
|
|
|
protected $idr = false; |
45
|
|
|
|
46
|
|
|
/** @var boolean */ |
47
|
|
|
protected $silent = false; |
48
|
|
|
|
49
|
|
|
/** @var string */ |
50
|
|
|
protected $binary; |
51
|
|
|
|
52
|
|
|
/** @var string */ |
53
|
|
|
protected $type; |
54
|
|
|
|
55
|
|
|
/** @var integer */ |
56
|
|
|
protected $id; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $user |
60
|
|
|
* @return static |
61
|
|
|
*/ |
62
|
1 |
|
public static function create($user = '') |
63
|
|
|
{ |
64
|
1 |
|
return new static($user); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param string $user |
69
|
|
|
*/ |
70
|
21 |
|
public function __construct($user = '') |
71
|
|
|
{ |
72
|
21 |
|
$this->user = $user; |
73
|
21 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Set the user. |
77
|
|
|
* |
78
|
|
|
* @param $user |
79
|
|
|
* |
80
|
|
|
* @return $this |
81
|
|
|
*/ |
82
|
1 |
|
public function user($user) |
83
|
|
|
{ |
84
|
1 |
|
$this->user = $user; |
85
|
|
|
|
86
|
1 |
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Set the content. |
91
|
|
|
* |
92
|
|
|
* @param $content |
93
|
|
|
* |
94
|
|
|
* @return $this |
95
|
|
|
*/ |
96
|
3 |
|
public function content($content) |
97
|
|
|
{ |
98
|
3 |
|
$this->content = $content; |
99
|
|
|
|
100
|
3 |
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Set the data. |
105
|
|
|
* |
106
|
|
|
* @param array $data |
107
|
|
|
* |
108
|
|
|
* @return $this |
109
|
|
|
*/ |
110
|
3 |
|
public function data($data) |
111
|
|
|
{ |
112
|
3 |
|
$this->data = $data; |
113
|
|
|
|
114
|
3 |
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Set the trackId. |
119
|
|
|
* |
120
|
|
|
* @param $trackId |
121
|
|
|
* |
122
|
|
|
* @return $this |
123
|
|
|
*/ |
124
|
1 |
|
public function trackId($trackId) |
125
|
|
|
{ |
126
|
1 |
|
$this->trackId = $trackId; |
127
|
|
|
|
128
|
1 |
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Set the inApp. |
133
|
|
|
* |
134
|
|
|
* @return $this |
135
|
|
|
*/ |
136
|
1 |
|
public function inApp() |
137
|
|
|
{ |
138
|
1 |
|
$this->inApp = true; |
139
|
|
|
|
140
|
1 |
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Set the live. |
145
|
|
|
* |
146
|
|
|
* @return $this |
147
|
|
|
*/ |
148
|
1 |
|
public function live() |
149
|
|
|
{ |
150
|
1 |
|
$this->live = true; |
151
|
|
|
|
152
|
1 |
|
return $this; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Set the useAsAlert. |
157
|
|
|
* |
158
|
|
|
* @param bool $title |
159
|
|
|
* @return $this |
160
|
|
|
*/ |
161
|
2 |
|
public function alert($title = true) |
162
|
|
|
{ |
163
|
2 |
|
if (is_bool($title)) { |
164
|
1 |
|
$this->useAsAlert = true; |
165
|
|
|
} else { |
166
|
1 |
|
$this->alertText = $title; |
167
|
|
|
} |
168
|
|
|
|
169
|
2 |
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Set the ttl. |
174
|
|
|
* |
175
|
|
|
* @param $ttl |
176
|
|
|
* |
177
|
|
|
* @return $this |
178
|
|
|
*/ |
179
|
1 |
|
public function ttl($ttl) |
180
|
|
|
{ |
181
|
1 |
|
$this->ttl = $ttl; |
182
|
|
|
|
183
|
1 |
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Set the fallback. |
188
|
|
|
* |
189
|
|
|
* @param array $fallback |
190
|
|
|
* |
191
|
|
|
* @return $this |
192
|
|
|
*/ |
193
|
1 |
|
public function fallback($fallback) |
194
|
|
|
{ |
195
|
1 |
|
$this->fallback = $fallback; |
196
|
|
|
|
197
|
1 |
|
return $this; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Set the clientId. |
202
|
|
|
* |
203
|
|
|
* @param $clientId |
204
|
|
|
* |
205
|
|
|
* @return $this |
206
|
|
|
*/ |
207
|
1 |
|
public function clientId($clientId) |
208
|
|
|
{ |
209
|
1 |
|
$this->clientId = $clientId; |
210
|
|
|
|
211
|
1 |
|
return $this; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Set the notification. |
216
|
|
|
* |
217
|
|
|
* @param array $notification |
218
|
|
|
* |
219
|
|
|
* @return $this |
220
|
|
|
*/ |
221
|
1 |
|
public function notification($notification) |
222
|
|
|
{ |
223
|
1 |
|
$this->notification = $notification; |
224
|
|
|
|
225
|
1 |
|
return $this; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Set the idr. |
230
|
|
|
* |
231
|
|
|
* @return $this |
232
|
|
|
*/ |
233
|
1 |
|
public function idr() |
234
|
|
|
{ |
235
|
1 |
|
$this->idr = true; |
236
|
|
|
|
237
|
1 |
|
return $this; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Set the silent. |
242
|
|
|
* |
243
|
|
|
* @return $this |
244
|
|
|
*/ |
245
|
1 |
|
public function silent() |
246
|
|
|
{ |
247
|
1 |
|
$this->silent = true; |
248
|
|
|
|
249
|
1 |
|
return $this; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Set the binary. |
254
|
|
|
* |
255
|
|
|
* @param $binary |
256
|
|
|
* |
257
|
|
|
* @return $this |
258
|
|
|
*/ |
259
|
1 |
|
public function binary($binary) |
260
|
|
|
{ |
261
|
1 |
|
$this->binary = $binary; |
262
|
|
|
|
263
|
1 |
|
return $this; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Set the type. |
268
|
|
|
* |
269
|
|
|
* @param $type |
270
|
|
|
* |
271
|
|
|
* @return $this |
272
|
|
|
*/ |
273
|
1 |
|
public function type($type) |
274
|
|
|
{ |
275
|
1 |
|
$this->type = $type; |
276
|
|
|
|
277
|
1 |
|
return $this; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Set the id. |
282
|
|
|
* |
283
|
|
|
* @param $id |
284
|
|
|
* |
285
|
|
|
* @return $this |
286
|
|
|
*/ |
287
|
1 |
|
public function id($id) |
288
|
|
|
{ |
289
|
1 |
|
$this->id = $id; |
290
|
|
|
|
291
|
1 |
|
return $this; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @return array |
296
|
|
|
*/ |
297
|
21 |
|
public function toArray() |
298
|
|
|
{ |
299
|
|
|
$parameters = [ |
300
|
21 |
|
'user' => $this->user, |
301
|
21 |
|
'content' => $this->content, |
302
|
|
|
]; |
303
|
21 |
|
if (count($this->data)) |
304
|
3 |
|
$parameters = array_merge($parameters, ['data' => $this->data]); |
305
|
|
|
|
306
|
21 |
|
if ($this->trackId) |
307
|
1 |
|
$parameters = array_merge($parameters, ['trackId' => $this->trackId]); |
308
|
|
|
|
309
|
21 |
|
if ($this->inApp) |
310
|
1 |
|
$parameters = array_merge($parameters, ['inApp' => true]); |
311
|
|
|
|
312
|
21 |
|
if ($this->live) |
313
|
1 |
|
$parameters = array_merge($parameters, ['live' => true]); |
314
|
|
|
|
315
|
21 |
|
if ($this->useAsAlert) |
316
|
1 |
|
$parameters = array_merge($parameters, ['useAsAlert' => true]); |
317
|
|
|
|
318
|
21 |
|
if ($this->useAsAlert) |
319
|
1 |
|
$parameters = array_merge($parameters, ['useAsAlert' => true]); |
320
|
|
|
|
321
|
21 |
|
if ($this->alertText) |
322
|
1 |
|
$parameters = array_merge($parameters, ['alertText' => $this->alertText]); |
323
|
|
|
|
324
|
21 |
|
if ($this->ttl) |
325
|
1 |
|
$parameters = array_merge($parameters, ['ttl' => $this->ttl]); |
326
|
|
|
|
327
|
21 |
|
if (count($this->fallback)) |
328
|
1 |
|
$parameters = array_merge($parameters, ['fallback' => $this->fallback]); |
329
|
|
|
|
330
|
21 |
|
if ($this->clientId) |
331
|
1 |
|
$parameters = array_merge($parameters, ['clientId' => $this->clientId]); |
332
|
|
|
|
333
|
21 |
|
if (count($this->notification)) |
334
|
1 |
|
$parameters = array_merge($parameters, ['notification' => $this->notification]); |
335
|
|
|
|
336
|
21 |
|
if ($this->idr) |
337
|
1 |
|
$parameters = array_merge($parameters, ['idr' => true]); |
338
|
|
|
|
339
|
21 |
|
if ($this->silent) |
340
|
1 |
|
$parameters = array_merge($parameters, ['silent' => true]); |
341
|
|
|
|
342
|
21 |
|
if ($this->binary) |
343
|
1 |
|
$parameters = array_merge($parameters, ['contentBinary' => $this->binary]); |
344
|
|
|
|
345
|
21 |
|
if ($this->type) |
346
|
1 |
|
$parameters = array_merge($parameters, ['contentType' => $this->type]); |
347
|
|
|
|
348
|
21 |
|
if ($this->id) |
349
|
1 |
|
$parameters = array_merge($parameters, ['id' => $this->id]); |
350
|
|
|
|
351
|
21 |
|
return $parameters; |
352
|
|
|
} |
353
|
|
|
} |
354
|
|
|
|