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 | * Set mutable content. |
||
190 | * |
||
191 | * @param bool $value |
||
192 | * @return Payload |
||
193 | */ |
||
194 | public function setMutableContent(bool $value): Payload |
||
200 | |||
201 | /** |
||
202 | * Get content availability. |
||
203 | * |
||
204 | * @return bool|null |
||
205 | */ |
||
206 | public function isContentAvailable() |
||
210 | |||
211 | /** |
||
212 | * Set category. |
||
213 | * |
||
214 | * @param string $value |
||
215 | * @return Payload |
||
216 | */ |
||
217 | public function setCategory(string $value): Payload |
||
223 | |||
224 | /** |
||
225 | * Get category. |
||
226 | * |
||
227 | * @return string|null |
||
228 | */ |
||
229 | public function getCategory() |
||
233 | |||
234 | /** |
||
235 | * Set thread-id. |
||
236 | * |
||
237 | * @param string $value |
||
238 | * @return Payload |
||
239 | */ |
||
240 | public function setThreadId(string $value): Payload |
||
246 | |||
247 | /** |
||
248 | * Get thread-id. |
||
249 | * |
||
250 | * @return string|null |
||
251 | */ |
||
252 | public function getThreadId() |
||
256 | |||
257 | /** |
||
258 | * Set custom value for Payload. |
||
259 | * |
||
260 | * @param string $key |
||
261 | * @param mixed $value |
||
262 | * @return Payload |
||
263 | * @throws InvalidPayloadException |
||
264 | */ |
||
265 | public function setCustomValue(string $key, $value): Payload |
||
275 | |||
276 | /** |
||
277 | * Get custom value. |
||
278 | * |
||
279 | * @param $key |
||
280 | * @return mixed |
||
281 | * @throws InvalidPayloadException |
||
282 | */ |
||
283 | public function getCustomValue($key) |
||
291 | |||
292 | /** |
||
293 | * Convert Payload to JSON. |
||
294 | * |
||
295 | * @return string |
||
296 | */ |
||
297 | public function toJson(): string |
||
301 | |||
302 | /** |
||
303 | * Specify data which should be serialized to JSON. |
||
304 | * |
||
305 | * @return array |
||
306 | * @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
||
307 | */ |
||
308 | public function jsonSerialize() |
||
346 | |||
347 | /** |
||
348 | * Get default payload structure. |
||
349 | * |
||
350 | * @return array |
||
351 | */ |
||
352 | private static function getDefaultPayloadStructure() |
||
356 | } |
||
357 |