|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\Apn; |
|
4
|
|
|
|
|
5
|
|
|
use Pushok\Notification; |
|
6
|
|
|
use Pushok\Payload; |
|
7
|
|
|
use Pushok\Payload\Alert; |
|
8
|
|
|
|
|
9
|
|
|
class ApnAdapter |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Convert an ApnMessage instance into a Zend Apns Message. |
|
13
|
|
|
* |
|
14
|
|
|
* @param \NotificationChannels\Apn\ApnMessage $message |
|
15
|
|
|
* @param string $token |
|
16
|
|
|
* @return \Pushok\Notification |
|
17
|
|
|
*/ |
|
18
|
6 |
|
public function adapt(ApnMessage $message, string $token) |
|
19
|
|
|
{ |
|
20
|
6 |
|
$alert = Alert::create(); |
|
21
|
|
|
|
|
22
|
6 |
|
if ($title = $message->title) { |
|
23
|
3 |
|
$alert->setTitle($title); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
6 |
|
if ($body = $message->body) { |
|
27
|
|
|
$alert->setBody($body); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
6 |
|
$payload = Payload::create() |
|
31
|
6 |
|
->setAlert($alert) |
|
32
|
6 |
|
->setContentAvailability((bool) $message->contentAvailable) |
|
33
|
6 |
|
->setMutableContent((bool) $message->mutableContent); |
|
34
|
|
|
|
|
35
|
6 |
|
if ($badge = $message->badge) { |
|
36
|
|
|
$payload->setBadge($badge); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
6 |
|
if ($sound = $message->sound) { |
|
40
|
|
|
$payload->setSound($sound); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
6 |
|
if ($category = $message->category) { |
|
44
|
|
|
$payload->setCategory($category); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
6 |
|
foreach ($message->custom as $key => $value) { |
|
48
|
|
|
$payload->setCustomValue($key, $value); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
6 |
|
if ($pushType = $message->pushType) { |
|
52
|
3 |
|
$payload->setPushType($pushType); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
6 |
|
$notification = new Notification($payload, $token); |
|
56
|
|
|
|
|
57
|
6 |
|
if ($expiresAt = $message->expiresAt) { |
|
58
|
|
|
$notification->setExpirationAt($expiresAt); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
6 |
|
return $notification; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|