1 | <?php |
||
22 | class Payload |
||
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_CATEGORY_KEY = 'category'; |
||
30 | const PAYLOAD_THREAD_ID_KEY = 'thread-id'; |
||
31 | |||
32 | const PAYLOAD_HTTP2_REGULAR_NOTIFICATION_MAXIMUM_SIZE = 4096; |
||
33 | const PAYLOAD_HTTP2_VOIP_NOTIFICATION_MAXIMUM_SIZE = 5120; |
||
34 | const PAYLOAD_BINARY_REGULAR_NOTIFICATION_MAXIMUM_SIZE = 2048; |
||
35 | |||
36 | /** |
||
37 | * The notification settings for your app on the user’s device determine whether an alert or banner is displayed. |
||
38 | * |
||
39 | * @var Alert |
||
40 | */ |
||
41 | private $alert; |
||
42 | |||
43 | /** |
||
44 | * The number to display as the badge of the app icon. |
||
45 | * If this property is absent, the badge is not changed. |
||
46 | * |
||
47 | * @var int |
||
48 | */ |
||
49 | private $badge; |
||
50 | |||
51 | /** |
||
52 | * The name of a sound file in the app bundle or in the Library/Sounds folder of the app’s data container. |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | private $sound; |
||
57 | |||
58 | /** |
||
59 | * Include this key with a value of true to configure a silent notification. |
||
60 | * |
||
61 | * @var bool |
||
62 | */ |
||
63 | private $contentAvailable; |
||
64 | |||
65 | /** |
||
66 | * Provide this key with a string value that represents the notification’s type. |
||
67 | * |
||
68 | * @var string |
||
69 | */ |
||
70 | private $category; |
||
71 | |||
72 | /** |
||
73 | * Provide this key with a string value that represents the app-specific identifier for grouping notifications. |
||
74 | * |
||
75 | * @var string |
||
76 | */ |
||
77 | private $threadId; |
||
78 | |||
79 | /** |
||
80 | * Payload custom values. |
||
81 | * |
||
82 | * @var array |
||
83 | */ |
||
84 | private $customValues; |
||
85 | |||
86 | protected function __constructor() |
||
89 | |||
90 | /** |
||
91 | * @return Payload |
||
92 | */ |
||
93 | public static function create(): Payload |
||
97 | |||
98 | /** |
||
99 | * Set Alert. |
||
100 | * |
||
101 | * @param Alert $alert |
||
102 | * @return Payload |
||
103 | */ |
||
104 | public function setAlert(Alert $alert): Payload |
||
110 | |||
111 | /** |
||
112 | * Get Alert. |
||
113 | * |
||
114 | * @return Alert|null |
||
115 | */ |
||
116 | public function getAlert() |
||
120 | |||
121 | /** |
||
122 | * Set badge. |
||
123 | * |
||
124 | * @param int $value |
||
125 | * @return Payload |
||
126 | */ |
||
127 | public function setBadge(int $value): Payload |
||
133 | |||
134 | /** |
||
135 | * Get badge. |
||
136 | * |
||
137 | * @return int|null |
||
138 | */ |
||
139 | public function getBadge() |
||
143 | |||
144 | /** |
||
145 | * Set sound. |
||
146 | * |
||
147 | * @param string $value |
||
148 | * @return Payload |
||
149 | */ |
||
150 | public function setSound(string $value): Payload |
||
156 | |||
157 | /** |
||
158 | * Get sound. |
||
159 | * |
||
160 | * @return string|null |
||
161 | */ |
||
162 | public function getSound() |
||
166 | |||
167 | /** |
||
168 | * Set content availability. |
||
169 | * |
||
170 | * @param bool $value |
||
171 | * @return Payload |
||
172 | */ |
||
173 | public function setContentAvailability(bool $value): Payload |
||
174 | { |
||
175 | $this->contentAvailable = $value; |
||
176 | |||
177 | return $this; |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Get content availability. |
||
182 | * |
||
183 | * @return bool|null |
||
184 | */ |
||
185 | public function isContentAvailable() |
||
189 | |||
190 | /** |
||
191 | * Set category. |
||
192 | * |
||
193 | * @param string $value |
||
194 | * @return Payload |
||
195 | */ |
||
196 | public function setCategory(string $value): Payload |
||
202 | |||
203 | /** |
||
204 | * Get category. |
||
205 | * |
||
206 | * @return string|null |
||
207 | */ |
||
208 | public function getCategory() |
||
212 | |||
213 | /** |
||
214 | * Set thread-id. |
||
215 | * |
||
216 | * @param string $value |
||
217 | * @return Payload |
||
218 | */ |
||
219 | public function setThreadId(string $value): Payload |
||
225 | |||
226 | /** |
||
227 | * Get thread-id. |
||
228 | * |
||
229 | * @return string|null |
||
230 | */ |
||
231 | public function getThreadId() |
||
235 | |||
236 | /** |
||
237 | * Set custom value for Payload. |
||
238 | * |
||
239 | * @param string $key |
||
240 | * @param mixed $value |
||
241 | * @return Payload |
||
242 | * @throws InvalidPayloadException |
||
243 | */ |
||
244 | public function setCustomValue(string $key, $value): Payload |
||
254 | |||
255 | /** |
||
256 | * Get custom value. |
||
257 | * |
||
258 | * @param $key |
||
259 | * @return mixed |
||
260 | * @throws InvalidPayloadException |
||
261 | */ |
||
262 | public function getCustomValue($key) |
||
270 | |||
271 | /** |
||
272 | * Convert Payload to JSON. |
||
273 | * |
||
274 | * @return string |
||
275 | */ |
||
276 | public function toJson(): string |
||
282 | |||
283 | /** |
||
284 | * Transform Payload object to array. |
||
285 | * |
||
286 | * @return array |
||
287 | */ |
||
288 | private function transform(): array |
||
322 | |||
323 | private static function getDefaultPayloadStructure() |
||
327 | } |
||
328 |