|
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
|
|
|
* Alert dictionary |
|
45
|
|
|
* |
|
46
|
|
|
* @var APNSAlert|null |
|
47
|
|
|
*/ |
|
48
|
|
|
private $alertDictionary; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* The number to display as the badge of the application icon |
|
52
|
|
|
* |
|
53
|
|
|
* @var integer |
|
54
|
|
|
*/ |
|
55
|
|
|
private $badge; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* The name of a sound file in the application bundle |
|
59
|
|
|
* |
|
60
|
|
|
* @var string |
|
61
|
|
|
*/ |
|
62
|
|
|
private $sound; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Category option for custom notification actions (iOS 8+) |
|
66
|
|
|
* |
|
67
|
|
|
* @var string |
|
68
|
|
|
*/ |
|
69
|
|
|
private $category; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Provide this key with a value of 1 to indicate that new content is available |
|
73
|
|
|
* |
|
74
|
|
|
* @var bool |
|
75
|
|
|
*/ |
|
76
|
|
|
private $contentAvailable; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Custom properties |
|
80
|
|
|
* |
|
81
|
|
|
* @var array |
|
82
|
|
|
*/ |
|
83
|
|
|
private $customPayloadData = array(); |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Safari url args |
|
87
|
|
|
* |
|
88
|
|
|
* @var array |
|
89
|
|
|
*/ |
|
90
|
|
|
private $urlArgs; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @var bool |
|
94
|
|
|
*/ |
|
95
|
|
|
private $mutableContent; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Gets message type |
|
99
|
|
|
* |
|
100
|
|
|
* @return string |
|
101
|
|
|
*/ |
|
102
|
|
|
public function getMessageType() |
|
103
|
|
|
{ |
|
104
|
|
|
return NotificationServices::APPLE_PUSH_NOTIFICATIONS_SERVICE; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @return string |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getAlert() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->alert; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @param string $alert |
|
117
|
|
|
* @return $this |
|
118
|
|
|
*/ |
|
119
|
|
|
public function setAlert($alert) |
|
120
|
|
|
{ |
|
121
|
|
|
if (!is_scalar($alert)) { |
|
122
|
|
|
$this->invalidArgumentException('Alert', 'a string'); |
|
123
|
|
|
} |
|
124
|
|
|
$this->alert = $alert; |
|
125
|
|
|
|
|
126
|
|
|
return $this; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @return APNSAlert|null |
|
131
|
|
|
*/ |
|
132
|
|
|
public function getAlertDictionary() |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->alertDictionary; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param APNSAlert $alertDictionary |
|
139
|
|
|
* @return APNS |
|
140
|
|
|
*/ |
|
141
|
|
|
public function setAlertDictionary(APNSAlert $alertDictionary) |
|
142
|
|
|
{ |
|
143
|
|
|
$this->alertDictionary = $alertDictionary; |
|
144
|
|
|
return $this; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @return int |
|
149
|
|
|
*/ |
|
150
|
|
|
public function getBadge() |
|
151
|
|
|
{ |
|
152
|
|
|
return $this->badge; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @param int $badge |
|
157
|
|
|
* @return $this |
|
158
|
|
|
*/ |
|
159
|
|
|
public function setBadge($badge) |
|
160
|
|
|
{ |
|
161
|
|
|
if (!is_int($badge)) { |
|
162
|
|
|
$this->invalidArgumentException('Badge', 'an integer'); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
$this->badge = $badge; |
|
166
|
|
|
|
|
167
|
|
|
return $this; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @return array |
|
172
|
|
|
*/ |
|
173
|
|
|
public function getCustomPayloadData() |
|
174
|
|
|
{ |
|
175
|
|
|
return $this->customPayloadData; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @param array $customPayloadData |
|
180
|
|
|
*/ |
|
181
|
|
|
public function setCustomPayloadData($customPayloadData) |
|
182
|
|
|
{ |
|
183
|
|
|
$this->customPayloadData = $customPayloadData; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @return boolean |
|
188
|
|
|
*/ |
|
189
|
|
|
public function isContentAvailable() |
|
190
|
|
|
{ |
|
191
|
|
|
return $this->contentAvailable; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @param boolean $contentAvailable |
|
196
|
|
|
* @return $this |
|
197
|
|
|
*/ |
|
198
|
|
|
public function setContentAvailable($contentAvailable) |
|
199
|
|
|
{ |
|
200
|
|
|
if (!is_bool($contentAvailable)) { |
|
201
|
|
|
$this->invalidArgumentException('ContentAvailable', 'a boolean'); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
$this->contentAvailable = $contentAvailable; |
|
205
|
|
|
|
|
206
|
|
|
return $this; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* @return int |
|
211
|
|
|
*/ |
|
212
|
|
|
public function getPriority() |
|
213
|
|
|
{ |
|
214
|
|
|
return $this->priority; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* @param int $priority |
|
219
|
|
|
*/ |
|
220
|
|
|
public function setPriority($priority) |
|
221
|
|
|
{ |
|
222
|
|
|
$this->priority = $priority; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* @return string |
|
227
|
|
|
*/ |
|
228
|
|
|
public function getSound() |
|
229
|
|
|
{ |
|
230
|
|
|
return $this->sound; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* @param string $sound |
|
235
|
|
|
* @return $this |
|
236
|
|
|
*/ |
|
237
|
|
|
public function setSound($sound) |
|
238
|
|
|
{ |
|
239
|
|
|
if (!is_scalar($sound)) { |
|
240
|
|
|
$this->invalidArgumentException('Sound', 'an string'); |
|
241
|
|
|
} |
|
242
|
|
|
$this->sound = $sound; |
|
243
|
|
|
|
|
244
|
|
|
return $this; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @return string |
|
249
|
|
|
*/ |
|
250
|
|
|
public function getCategory() |
|
251
|
|
|
{ |
|
252
|
|
|
return $this->category; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* @param string $category |
|
257
|
|
|
* @return $this |
|
258
|
|
|
*/ |
|
259
|
|
|
public function setCategory($category) |
|
260
|
|
|
{ |
|
261
|
|
|
if (!is_scalar($category)) { |
|
262
|
|
|
$this->invalidArgumentException('Category', 'an string'); |
|
263
|
|
|
} |
|
264
|
|
|
$this->category = $category; |
|
265
|
|
|
|
|
266
|
|
|
return $this; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* @return array |
|
271
|
|
|
*/ |
|
272
|
|
|
public function getUrlArgs() |
|
273
|
|
|
{ |
|
274
|
|
|
return $this->urlArgs; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* @param array $urlArgs |
|
279
|
|
|
* @return $this |
|
280
|
|
|
*/ |
|
281
|
|
|
public function setUrlArgs($urlArgs) |
|
282
|
|
|
{ |
|
283
|
|
|
$this->urlArgs = $urlArgs; |
|
284
|
|
|
return $this; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
/** |
|
288
|
|
|
* @return boolean |
|
289
|
|
|
*/ |
|
290
|
|
|
public function isMutableContent() |
|
291
|
|
|
{ |
|
292
|
|
|
return $this->mutableContent; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
/** |
|
296
|
|
|
* @param boolean $mutableContent |
|
297
|
|
|
* @return $this |
|
298
|
|
|
*/ |
|
299
|
|
|
public function setMutableContent($mutableContent) |
|
300
|
|
|
{ |
|
301
|
|
|
$this->mutableContent = (bool) $mutableContent; |
|
302
|
|
|
return $this; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
/** |
|
306
|
|
|
* {@inheritdoc} |
|
307
|
|
|
*/ |
|
308
|
|
|
public function validateRecipient($token) |
|
309
|
|
|
{ |
|
310
|
|
|
if (!ctype_xdigit($token)) { |
|
311
|
|
|
throw new InvalidArgumentException(sprintf( |
|
312
|
|
|
'Device token must be a hexadecimal digit. Token given: "%s"', |
|
313
|
|
|
$token |
|
314
|
|
|
)); |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
if (strlen($token) != 64) { |
|
318
|
|
|
throw new InvalidArgumentException(sprintf( |
|
319
|
|
|
'Device token must be a 64 charsets, Token length given: %d.', |
|
320
|
|
|
mb_strlen($token) |
|
321
|
|
|
)); |
|
322
|
|
|
} |
|
323
|
|
|
return true; |
|
324
|
|
|
} |
|
325
|
|
|
} |
|
326
|
|
|
|