1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WZRD\Push; |
4
|
|
|
|
5
|
|
|
use WZRD\Contracts\Push\Notification as NotificationContract; |
6
|
|
|
use WZRD\Contracts\Push\Pusher; |
7
|
|
|
use ZendService\Apple\Apns\Client\Message as Client; |
8
|
|
|
use ZendService\Apple\Apns\Message; |
9
|
|
|
|
10
|
|
|
class ZendApnsPusher implements Pusher |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Zend APNS. |
14
|
|
|
* |
15
|
|
|
* @var ZendService\Apple\Apns\Client\Message |
16
|
|
|
*/ |
17
|
|
|
private $client; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Construct with Zend APNS Client instance. |
21
|
|
|
* |
22
|
|
|
* @param ZendService\Apple\Apns\Client\Message $client |
23
|
|
|
*/ |
24
|
|
|
public function __construct(Client $client) |
25
|
|
|
{ |
26
|
|
|
$this->client = $client; |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Push message. |
31
|
|
|
* |
32
|
|
|
* @param WZRD\Contracts\Push\Notification $notification |
33
|
|
|
* @param array $options |
34
|
|
|
*/ |
35
|
|
|
public function push(NotificationContract $notification, array $options = []) |
36
|
|
|
{ |
37
|
|
|
// Check the supported platforms |
38
|
|
|
if (count(array_intersect($notification->getTargetedPlatforms(), $this->getSupportedPlatforms())) == 0) { |
39
|
|
|
return; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
// Platforms & devices options |
43
|
|
|
$devices = $platforms_options = []; |
44
|
|
View Code Duplication |
foreach ($notification->getDevices() as $platform => $data) { |
|
|
|
|
45
|
|
|
if (in_array($platform, $this->getSupportedPlatforms())) { |
46
|
|
|
$platforms_options = array_merge($platforms_options, $data['options']); |
47
|
|
|
$devices = array_merge($devices, $data['devices']); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// Push ! |
52
|
|
|
foreach ($devices as $device) { |
53
|
|
|
$message = new Message(); |
54
|
|
|
$message->setToken($device); |
55
|
|
|
$message->setCustom($notification->getData()); |
56
|
|
|
$message->setAlert($notification->getMessage()); |
57
|
|
|
|
58
|
|
|
if (!empty($platforms_options['badge'])) { |
59
|
|
|
$message->setBadge($platforms_options['badge']); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if (!empty($platforms_options['sound'])) { |
63
|
|
|
$message->setSound($platforms_options['sound']); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$this->client->send($message); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Listen feedback service. |
72
|
|
|
* |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function feedback() |
76
|
|
|
{ |
77
|
|
|
$feedback = $this->client->feedback(); |
78
|
|
|
|
79
|
|
|
return $feedback; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get supported platforms. |
84
|
|
|
* |
85
|
|
|
* @return array |
86
|
|
|
*/ |
87
|
|
|
public function getSupportedPlatforms() |
88
|
|
|
{ |
89
|
|
|
return ['ios']; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..