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
|
|
|
* @var bool |
87
|
|
|
*/ |
88
|
|
|
private $mutableContent; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Gets message type |
92
|
|
|
* |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getMessageType() |
96
|
|
|
{ |
97
|
|
|
return NotificationServices::APPLE_PUSH_NOTIFICATIONS_SERVICE; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function getAlert() |
104
|
|
|
{ |
105
|
|
|
return $this->alert; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param string $alert |
110
|
|
|
* @return $this |
111
|
|
|
*/ |
112
|
|
|
public function setAlert($alert) |
113
|
|
|
{ |
114
|
|
|
if (!is_scalar($alert)) { |
115
|
|
|
$this->invalidArgumentException('Alert', 'a string'); |
116
|
|
|
} |
117
|
|
|
$this->alert = $alert; |
118
|
|
|
|
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return int |
124
|
|
|
*/ |
125
|
|
|
public function getBadge() |
126
|
|
|
{ |
127
|
|
|
return $this->badge; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param int $badge |
132
|
|
|
* @return $this |
133
|
|
|
*/ |
134
|
|
|
public function setBadge($badge) |
135
|
|
|
{ |
136
|
|
|
if (!is_int($badge)) { |
137
|
|
|
$this->invalidArgumentException('Badge', 'an integer'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
$this->badge = $badge; |
141
|
|
|
|
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return array |
147
|
|
|
*/ |
148
|
|
|
public function getCustomPayloadData() |
149
|
|
|
{ |
150
|
|
|
return $this->customPayloadData; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param array $customPayloadData |
155
|
|
|
*/ |
156
|
|
|
public function setCustomPayloadData($customPayloadData) |
157
|
|
|
{ |
158
|
|
|
$this->customPayloadData = $customPayloadData; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return boolean |
163
|
|
|
*/ |
164
|
|
|
public function isContentAvailable() |
165
|
|
|
{ |
166
|
|
|
return $this->contentAvailable; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @param boolean $contentAvailable |
171
|
|
|
* @return $this |
172
|
|
|
*/ |
173
|
|
|
public function setContentAvailable($contentAvailable) |
174
|
|
|
{ |
175
|
|
|
if (!is_bool($contentAvailable)) { |
176
|
|
|
$this->invalidArgumentException('ContentAvailable', 'a boolean'); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
$this->contentAvailable = $contentAvailable; |
180
|
|
|
|
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @return int |
186
|
|
|
*/ |
187
|
|
|
public function getPriority() |
188
|
|
|
{ |
189
|
|
|
return $this->priority; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param int $priority |
194
|
|
|
*/ |
195
|
|
|
public function setPriority($priority) |
196
|
|
|
{ |
197
|
|
|
$this->priority = $priority; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @return string |
202
|
|
|
*/ |
203
|
|
|
public function getSound() |
204
|
|
|
{ |
205
|
|
|
return $this->sound; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param string $sound |
210
|
|
|
* @return $this |
211
|
|
|
*/ |
212
|
|
|
public function setSound($sound) |
213
|
|
|
{ |
214
|
|
|
if (!is_scalar($sound)) { |
215
|
|
|
$this->invalidArgumentException('Sound', 'an string'); |
216
|
|
|
} |
217
|
|
|
$this->sound = $sound; |
218
|
|
|
|
219
|
|
|
return $this; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @return string |
224
|
|
|
*/ |
225
|
|
|
public function getCategory() |
226
|
|
|
{ |
227
|
|
|
return $this->category; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @param string $category |
232
|
|
|
* @return $this |
233
|
|
|
*/ |
234
|
|
|
public function setCategory($category) |
235
|
|
|
{ |
236
|
|
|
if (!is_scalar($category)) { |
237
|
|
|
$this->invalidArgumentException('Category', 'an string'); |
238
|
|
|
} |
239
|
|
|
$this->category = $category; |
240
|
|
|
|
241
|
|
|
return $this; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @return array |
246
|
|
|
*/ |
247
|
|
|
public function getUrlArgs() |
248
|
|
|
{ |
249
|
|
|
return $this->urlArgs; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @param array $urlArgs |
254
|
|
|
* @return $this |
255
|
|
|
*/ |
256
|
|
|
public function setUrlArgs($urlArgs) |
257
|
|
|
{ |
258
|
|
|
$this->urlArgs = $urlArgs; |
259
|
|
|
return $this; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @return boolean |
264
|
|
|
*/ |
265
|
|
|
public function isMutableContent() |
266
|
|
|
{ |
267
|
|
|
return $this->mutableContent; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @param boolean $mutableContent |
272
|
|
|
* @return $this |
273
|
|
|
*/ |
274
|
|
|
public function setMutableContent($mutableContent) |
275
|
|
|
{ |
276
|
|
|
$this->mutableContent = (bool) $mutableContent; |
277
|
|
|
return $this; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* {@inheritdoc} |
282
|
|
|
*/ |
283
|
|
|
public function validateRecipient($token) |
284
|
|
|
{ |
285
|
|
|
if (!ctype_xdigit($token)) { |
286
|
|
|
throw new InvalidArgumentException(sprintf( |
287
|
|
|
'Device token must be a hexadecimal digit. Token given: "%s"', |
288
|
|
|
$token |
289
|
|
|
)); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
if (strlen($token) != 64) { |
293
|
|
|
throw new InvalidArgumentException(sprintf( |
294
|
|
|
'Device token must be a 64 charsets, Token length given: %d.', |
295
|
|
|
mb_strlen($token) |
296
|
|
|
)); |
297
|
|
|
} |
298
|
|
|
return true; |
299
|
|
|
} |
300
|
|
|
} |
301
|
|
|
|