-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathApnMessage.php
More file actions
431 lines (352 loc) · 8.62 KB
/
ApnMessage.php
File metadata and controls
431 lines (352 loc) · 8.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
<?php
namespace NotificationChannels\Apn;
use DateTime;
use Pushok\Client;
use Pushok\Payload\Sound;
class ApnMessage
{
/**
* The title of the notification.
*/
public ?string $title = null;
/**
* The subtitle of the notification.
*/
public ?string $subtitle = null;
/**
* The body of the notification.
*/
public ?string $body = null;
/**
* The badge of the notification.
*/
public ?int $badge;
/**
* The sound of the notification.
*/
public null|string|Sound $sound = null;
/**
* The interruption level of the notification.
*/
public ?string $interruptionLevel = null;
/**
* The category for action button.
*/
public ?string $category = null;
/**
* The thread ID of the notification.
*/
public ?string $threadId = null;
/**
* Value indicating incoming resource in the notification.
*/
public ?int $contentAvailable = null;
/**
* The key to a title string in the Localizable.strings file for the current localization.
*/
public ?string $titleLocKey = null;
/**
* Variable string values to appear in place of the format specifiers in title-loc-key.
*/
public ?array $titleLocArgs = null;
/**
* If a string is specified, the iOS system displays an alert that includes the Close and View buttons.
*/
public ?string $actionLocKey = null;
/**
* A key to an alert-message string in a Localizable.strings file for the current localization.
*/
public ?string $locKey = null;
/**
* Variable string values to appear in place of the format specifiers in loc-key.
*/
public ?array $locArgs = null;
/**
* Additional data of the notification.
*/
public array $custom = [];
/**
* URL arguments of the notification.
*/
public array $urlArgs = [];
/**
* Value indicating the push type.
*/
public ?ApnMessagePushType $pushType = null;
/**
* The expiration time of the notification.
*/
public ?DateTime $expiresAt = null;
/**
* ID for the collapsing of similar notifications.
*/
public ?string $collapseId = null;
/**
* A canonical UUID that is the unique ID for the notification.
* APNs includes this value when reporting the error to your server.
*/
public ?string $apnsId = null;
/**
* The message priority.
*/
public ?ApnMessagePriority $priority = null;
/**
* Message specific client.
*/
public ?Client $client = null;
/**
* The notification service app extension flag.
*/
public ?int $mutableContent = null;
/**
* Custom alert for Edamov/Pushok.
*
* @var string|array|null
*/
public $customAlert = null;
/**
* Create a new messages instance.
*/
public function __construct(
?string $title = null,
?string $body = null,
array $custom = [],
?int $badge = null,
) {
$this->title = $title;
$this->body = $body;
$this->custom = $custom;
$this->badge = $badge;
}
/**
* Create a new message instance.
*/
public static function create(
?string $title = null,
?string $body = null,
array $custom = [],
?int $badge = null,
): static {
return new static($title, $body, $custom, $badge);
}
/**
* Set the alert title of the notification.
*/
public function title(?string $title): self
{
$this->title = $title;
return $this;
}
/**
* Set the alert subtitle of the notification.
*/
public function subtitle(?string $subtitle): self
{
$this->subtitle = $subtitle;
return $this;
}
/**
* Set the alert message of the notification.
*/
public function body(?string $body): self
{
$this->body = $body;
return $this;
}
/**
* Set the badge of the notification.
*/
public function badge(?int $badge): self
{
$this->badge = $badge;
return $this;
}
/**
* Set the sound of the notification.
*/
public function sound(null|string|Sound $sound = 'default'): self
{
$this->sound = $sound;
return $this;
}
/**
* Set the interruptionLevel of the notification.
*/
public function interruptionLevel(
string|ApnMessageInterruptionLevel|null $interruptionLevel = 'active',
): self {
$this->interruptionLevel =
$interruptionLevel instanceof ApnMessageInterruptionLevel
? $interruptionLevel->value
: $interruptionLevel;
return $this;
}
/**
* Set category of the notification.
* */
public function category(?string $category): self
{
$this->category = $category;
return $this;
}
/**
* Set thread ID of the notification.
* */
public function threadId(?string $threadId): self
{
$this->threadId = $threadId;
return $this;
}
/**
* Set content available value of the notification.
*/
public function contentAvailable(?int $value = 1): self
{
$this->contentAvailable = $value;
return $this;
}
/**
* Set the push type of the notification.
*/
public function pushType(?ApnMessagePushType $pushType): self
{
$this->pushType = $pushType;
return $this;
}
/**
* Set the expiration time for the message.
*/
public function expiresAt(DateTime $expiresAt): self
{
$this->expiresAt = $expiresAt;
return $this;
}
/**
* Set the collapse ID of the notification.
*/
public function collapseId(?string $collapseId): self
{
$this->collapseId = $collapseId;
return $this;
}
/**
* Set the APNS ID.
*/
public function apnsId(?string $apnsId): self
{
$this->apnsId = $apnsId;
return $this;
}
/**
* Set the message priority.
*/
public function priority(ApnMessagePriority $priority): self
{
$this->priority = $priority;
return $this;
}
/**
* Set a title-loc-key.
*/
public function titleLocKey(?string $titleLocKey = null): self
{
$this->titleLocKey = $titleLocKey;
return $this;
}
/**
* Set the title-loc-args.
*/
public function titleLocArgs(?array $titleLocArgs = null): self
{
$this->titleLocArgs = $titleLocArgs;
return $this;
}
/**
* Set an action-loc-key.
*/
public function actionLocKey($actionLocKey = null): self
{
$this->actionLocKey = $actionLocKey;
return $this;
}
/**
* Set a loc-key.
*/
public function locKey(?string $locKey): self
{
$this->locKey = $locKey;
return $this;
}
/**
* Set the loc-args.
*/
public function locArgs(?array $locArgs): self
{
$this->locArgs = $locArgs;
return $this;
}
/**
* Sets custom alert value as JSON or Array.
*
* @param string|array $customAlert
*/
public function customAlert($customAlert): self
{
$this->customAlert = $customAlert;
return $this;
}
/**
* Add custom data to the notification.
*/
public function custom(array|string $custom, mixed $value = null): self
{
if (is_array($custom)) {
$this->custom = $custom;
} else {
$this->custom[$custom] = $value;
}
return $this;
}
/**
* Add a URL argument to the notification.
*/
public function urlArg(string $key, mixed $value): self
{
$this->urlArgs[$key] = $value;
return $this;
}
/**
* Override the URL arguemnts of the notification.
*/
public function urlArgs(array $urlArgs): self
{
$this->urlArgs = $urlArgs;
return $this;
}
/**
* Add an action to the notification.
*/
public function action(string $action, mixed $params = null): self
{
return $this->custom('action', [
'action' => $action,
'params' => $params,
]);
}
/**
* Set message specific client.
*/
public function via(Client $client): self
{
$this->client = $client;
return $this;
}
/**
* Set mutable content value of the notification.
*/
public function mutableContent(?int $value = 1): self
{
$this->mutableContent = $value;
return $this;
}
}