1 | <?php |
||
22 | class Payload implements \JsonSerializable |
||
23 | { |
||
24 | const PAYLOAD_ROOT_KEY = 'aps'; |
||
25 | const PAYLOAD_ALERT_KEY = 'alert'; |
||
26 | const PAYLOAD_BADGE_KEY = 'badge'; |
||
27 | const PAYLOAD_SOUND_KEY = 'sound'; |
||
28 | const PAYLOAD_CONTENT_AVAILABLE_KEY = 'content-available'; |
||
29 | const PAYLOAD_MUTABLE_CONTENT_KEY = 'mutable-content'; |
||
30 | const PAYLOAD_CATEGORY_KEY = 'category'; |
||
31 | const PAYLOAD_THREAD_ID_KEY = 'thread-id'; |
||
32 | |||
33 | const PAYLOAD_HTTP2_REGULAR_NOTIFICATION_MAXIMUM_SIZE = 4096; |
||
34 | const PAYLOAD_HTTP2_VOIP_NOTIFICATION_MAXIMUM_SIZE = 5120; |
||
35 | const PAYLOAD_BINARY_REGULAR_NOTIFICATION_MAXIMUM_SIZE = 2048; |
||
36 | |||
37 | /** |
||
38 | * The notification settings for your app on the user’s device determine whether an alert or banner is displayed. |
||
39 | * |
||
40 | * @var Alert |
||
41 | */ |
||
42 | private $alert; |
||
43 | |||
44 | /** |
||
45 | * The number to display as the badge of the app icon. |
||
46 | * If this property is absent, the badge is not changed. |
||
47 | * |
||
48 | * @var int |
||
49 | */ |
||
50 | private $badge; |
||
51 | |||
52 | /** |
||
53 | * The name of a sound file in the app bundle or in the Library/Sounds folder of the app’s data container. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | private $sound; |
||
58 | |||
59 | /** |
||
60 | * Include this key with a value of true to configure a silent notification. |
||
61 | * |
||
62 | * @var bool |
||
63 | */ |
||
64 | private $contentAvailable; |
||
65 | |||
66 | /** |
||
67 | * Include this key with a value of true to configure a mutable content notification. |
||
68 | * |
||
69 | * @var bool |
||
70 | */ |
||
71 | private $mutableContent; |
||
72 | |||
73 | /** |
||
74 | * Provide this key with a string value that represents the notification’s type. |
||
75 | * |
||
76 | * @var string |
||
77 | */ |
||
78 | private $category; |
||
79 | |||
80 | /** |
||
81 | * Provide this key with a string value that represents the app-specific identifier for grouping notifications. |
||
82 | * |
||
83 | * @var string |
||
84 | */ |
||
85 | private $threadId; |
||
86 | |||
87 | /** |
||
88 | * Payload custom values. |
||
89 | * |
||
90 | * @var array |
||
91 | */ |
||
92 | private $customValues; |
||
93 | |||
94 | protected function __construct() |
||
97 | |||
98 | /** |
||
99 | * @return Payload |
||
100 | */ |
||
101 | public static function create(): Payload |
||
105 | |||
106 | /** |
||
107 | * Set Alert. |
||
108 | * |
||
109 | * @param Alert $alert |
||
110 | * @return Payload |
||
111 | */ |
||
112 | public function setAlert(Alert $alert): Payload |
||
118 | |||
119 | /** |
||
120 | * Get Alert. |
||
121 | * |
||
122 | * @return Alert|null |
||
123 | */ |
||
124 | public function getAlert() |
||
128 | |||
129 | /** |
||
130 | * Set badge. |
||
131 | * |
||
132 | * @param int $value |
||
133 | * @return Payload |
||
134 | */ |
||
135 | public function setBadge(int $value): Payload |
||
141 | |||
142 | /** |
||
143 | * Get badge. |
||
144 | * |
||
145 | * @return int|null |
||
146 | */ |
||
147 | public function getBadge() |
||
151 | |||
152 | /** |
||
153 | * Set sound. |
||
154 | * |
||
155 | * @param string $value |
||
156 | * @return Payload |
||
157 | */ |
||
158 | public function setSound(string $value): Payload |
||
164 | |||
165 | /** |
||
166 | * Get sound. |
||
167 | * |
||
168 | * @return string|null |
||
169 | */ |
||
170 | public function getSound() |
||
174 | |||
175 | /** |
||
176 | * Set content availability. |
||
177 | * |
||
178 | * @param bool $value |
||
179 | * @return Payload |
||
180 | */ |
||
181 | public function setContentAvailability(bool $value): Payload |
||
187 | |||
188 | /** |
||
189 | * Get content availability. |
||
190 | * |
||
191 | * @return bool|null |
||
192 | */ |
||
193 | public function isContentAvailable() |
||
197 | |||
198 | /** |
||
199 | * Set the mutable-content key for Notification Service Extensions on iOS10. |
||
200 | * @see http://bit.ly/mutable-content |
||
201 | * |
||
202 | * @param bool $value |
||
203 | * @return Payload |
||
204 | */ |
||
205 | public function setMutableContent(bool $value): Payload |
||
211 | |||
212 | /** |
||
213 | * Is content mutable. |
||
214 | * |
||
215 | * @return bool|null |
||
216 | */ |
||
217 | public function hasMutableContent() |
||
221 | |||
222 | /** |
||
223 | * Set category. |
||
224 | * |
||
225 | * @param string $value |
||
226 | * @return Payload |
||
227 | */ |
||
228 | public function setCategory(string $value): Payload |
||
234 | |||
235 | /** |
||
236 | * Get category. |
||
237 | * |
||
238 | * @return string|null |
||
239 | */ |
||
240 | public function getCategory() |
||
244 | |||
245 | /** |
||
246 | * Set thread-id. |
||
247 | * |
||
248 | * @param string $value |
||
249 | * @return Payload |
||
250 | */ |
||
251 | public function setThreadId(string $value): Payload |
||
257 | |||
258 | /** |
||
259 | * Get thread-id. |
||
260 | * |
||
261 | * @return string|null |
||
262 | */ |
||
263 | public function getThreadId() |
||
267 | |||
268 | /** |
||
269 | * Set custom value for Payload. |
||
270 | * |
||
271 | * @param string $key |
||
272 | * @param mixed $value |
||
273 | * @return Payload |
||
274 | * @throws InvalidPayloadException |
||
275 | */ |
||
276 | public function setCustomValue(string $key, $value): Payload |
||
286 | |||
287 | /** |
||
288 | * Get custom value. |
||
289 | * |
||
290 | * @param $key |
||
291 | * @return mixed |
||
292 | * @throws InvalidPayloadException |
||
293 | */ |
||
294 | public function getCustomValue($key) |
||
302 | |||
303 | /** |
||
304 | * Convert Payload to JSON. |
||
305 | * |
||
306 | * @return string |
||
307 | */ |
||
308 | public function toJson(): string |
||
312 | |||
313 | /** |
||
314 | * Specify data which should be serialized to JSON. |
||
315 | * |
||
316 | * @return array |
||
317 | * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
||
318 | */ |
||
319 | public function jsonSerialize() |
||
357 | |||
358 | /** |
||
359 | * Get default payload structure. |
||
360 | * |
||
361 | * @return array |
||
362 | */ |
||
363 | private static function getDefaultPayloadStructure() |
||
367 | } |
||
368 |