|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* (c) Alexander Zhukov <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Zbox\UnifiedPush\Message\Type; |
|
11
|
|
|
|
|
12
|
|
|
use Zbox\UnifiedPush\Message\MessageBase; |
|
13
|
|
|
use Zbox\UnifiedPush\NotificationService\NotificationServices; |
|
14
|
|
|
use Zbox\UnifiedPush\Exception\InvalidArgumentException; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class APNS |
|
18
|
|
|
* @package Zbox\UnifiedPush\Message\Type |
|
19
|
|
|
*/ |
|
20
|
|
|
class APNS extends MessageBase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* APNs does not support multicast sending |
|
24
|
|
|
*/ |
|
25
|
|
|
const MAX_RECIPIENTS_PER_MESSAGE_COUNT = 1; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The message’s priority. Provide one of the following values: |
|
29
|
|
|
* - 10 The push message is sent immediately |
|
30
|
|
|
* - 5 The push message is sent at a time that conserves power on the device receiving it |
|
31
|
|
|
* |
|
32
|
|
|
* @var integer |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $priority; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Message text of an alert |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
private $alert; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* The number to display as the badge of the application icon |
|
45
|
|
|
* |
|
46
|
|
|
* @var integer |
|
47
|
|
|
*/ |
|
48
|
|
|
private $badge; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* The name of a sound file in the application bundle |
|
52
|
|
|
* |
|
53
|
|
|
* @var string |
|
54
|
|
|
*/ |
|
55
|
|
|
private $sound; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Category option for custom notification actions (iOS 8+) |
|
59
|
|
|
* |
|
60
|
|
|
* @var string |
|
61
|
|
|
*/ |
|
62
|
|
|
private $category; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Provide this key with a value of 1 to indicate that new content is available |
|
66
|
|
|
* |
|
67
|
|
|
* @var bool |
|
68
|
|
|
*/ |
|
69
|
|
|
private $contentAvailable; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Custom properties |
|
73
|
|
|
* |
|
74
|
|
|
* @var array |
|
75
|
|
|
*/ |
|
76
|
|
|
private $customPayloadData = array(); |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Safari url args |
|
80
|
|
|
* |
|
81
|
|
|
* @var array |
|
82
|
|
|
*/ |
|
83
|
|
|
private $urlArgs; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Gets message type |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getMessageType() |
|
91
|
|
|
{ |
|
92
|
|
|
return NotificationServices::APPLE_PUSH_NOTIFICATIONS_SERVICE; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getAlert() |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->alert; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param string $alert |
|
105
|
|
|
* @return $this |
|
106
|
|
|
*/ |
|
107
|
|
|
public function setAlert($alert) |
|
108
|
|
|
{ |
|
109
|
|
|
if (!is_scalar($alert)) { |
|
110
|
|
|
$this->invalidArgumentException('Alert', 'a string'); |
|
111
|
|
|
} |
|
112
|
|
|
$this->alert = $alert; |
|
113
|
|
|
|
|
114
|
|
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return int |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getBadge() |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->badge; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @param int $badge |
|
127
|
|
|
* @return $this |
|
128
|
|
|
*/ |
|
129
|
|
|
public function setBadge($badge) |
|
130
|
|
|
{ |
|
131
|
|
|
if (!is_int($badge)) { |
|
132
|
|
|
$this->invalidArgumentException('Badge', 'an integer'); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
$this->badge = $badge; |
|
136
|
|
|
|
|
137
|
|
|
return $this; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @return array |
|
142
|
|
|
*/ |
|
143
|
|
|
public function getCustomPayloadData() |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->customPayloadData; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @param array $customPayloadData |
|
150
|
|
|
*/ |
|
151
|
|
|
public function setCustomPayloadData($customPayloadData) |
|
152
|
|
|
{ |
|
153
|
|
|
$this->customPayloadData = $customPayloadData; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return boolean |
|
158
|
|
|
*/ |
|
159
|
|
|
public function isContentAvailable() |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->contentAvailable; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @param boolean $contentAvailable |
|
166
|
|
|
* @return $this |
|
167
|
|
|
*/ |
|
168
|
|
|
public function setContentAvailable($contentAvailable) |
|
169
|
|
|
{ |
|
170
|
|
|
if (!is_bool($contentAvailable)) { |
|
171
|
|
|
$this->invalidArgumentException('ContentAvailable', 'a boolean'); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
$this->contentAvailable = $contentAvailable; |
|
175
|
|
|
|
|
176
|
|
|
return $this; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @return int |
|
181
|
|
|
*/ |
|
182
|
|
|
public function getPriority() |
|
183
|
|
|
{ |
|
184
|
|
|
return $this->priority; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @param int $priority |
|
189
|
|
|
*/ |
|
190
|
|
|
public function setPriority($priority) |
|
191
|
|
|
{ |
|
192
|
|
|
$this->priority = $priority; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @return string |
|
197
|
|
|
*/ |
|
198
|
|
|
public function getSound() |
|
199
|
|
|
{ |
|
200
|
|
|
return $this->sound; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* @param string $sound |
|
205
|
|
|
* @return $this |
|
206
|
|
|
*/ |
|
207
|
|
|
public function setSound($sound) |
|
208
|
|
|
{ |
|
209
|
|
|
if (!is_scalar($sound)) { |
|
210
|
|
|
$this->invalidArgumentException('Sound', 'an string'); |
|
211
|
|
|
} |
|
212
|
|
|
$this->sound = $sound; |
|
213
|
|
|
|
|
214
|
|
|
return $this; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* @return string |
|
219
|
|
|
*/ |
|
220
|
|
|
public function getCategory() |
|
221
|
|
|
{ |
|
222
|
|
|
return $this->category; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* @param string $category |
|
227
|
|
|
* @return $this |
|
228
|
|
|
*/ |
|
229
|
|
|
public function setCategory($category) |
|
230
|
|
|
{ |
|
231
|
|
|
if (!is_scalar($category)) { |
|
232
|
|
|
$this->invalidArgumentException('Category', 'an string'); |
|
233
|
|
|
} |
|
234
|
|
|
$this->category = $category; |
|
235
|
|
|
|
|
236
|
|
|
return $this; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* @return array |
|
241
|
|
|
*/ |
|
242
|
|
|
public function getUrlArgs() |
|
243
|
|
|
{ |
|
244
|
|
|
return $this->urlArgs; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @param array $urlArgs |
|
249
|
|
|
* @return $this |
|
250
|
|
|
*/ |
|
251
|
|
|
public function setUrlArgs($urlArgs) |
|
252
|
|
|
{ |
|
253
|
|
|
$this->urlArgs = $urlArgs; |
|
254
|
|
|
return $this; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* {@inheritdoc} |
|
259
|
|
|
*/ |
|
260
|
|
|
public function validateRecipient($token) |
|
261
|
|
|
{ |
|
262
|
|
|
if (!ctype_xdigit($token)) { |
|
263
|
|
|
throw new InvalidArgumentException(sprintf( |
|
264
|
|
|
'Device token must be a hexadecimal digit. Token given: "%s"', |
|
265
|
|
|
$token |
|
266
|
|
|
)); |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
if (strlen($token) != 64) { |
|
270
|
|
|
throw new InvalidArgumentException(sprintf( |
|
271
|
|
|
'Device token must be a 64 charsets, Token length given: %d.', |
|
272
|
|
|
mb_strlen($token) |
|
273
|
|
|
)); |
|
274
|
|
|
} |
|
275
|
|
|
return true; |
|
276
|
|
|
} |
|
277
|
|
|
} |
|
278
|
|
|
|