1 | <?php |
||
8 | class PusherMessage |
||
9 | { |
||
10 | /** |
||
11 | * The device platform (iOS/Android). |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $platform = 'iOS'; |
||
16 | |||
17 | /** |
||
18 | * The message title. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $title; |
||
23 | |||
24 | /** |
||
25 | * The message body. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $body; |
||
30 | |||
31 | /** |
||
32 | * The phone number the message should be sent from. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $sound = 'default'; |
||
37 | |||
38 | /** |
||
39 | * The message icon (Android). |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $icon; |
||
44 | |||
45 | /** |
||
46 | * The number to display next to the push notification (iOS). |
||
47 | * |
||
48 | * @var int |
||
49 | */ |
||
50 | protected $badge; |
||
51 | |||
52 | /** |
||
53 | * Extra options that will get added to the message. |
||
54 | * |
||
55 | * @var array |
||
56 | */ |
||
57 | protected $options = []; |
||
58 | |||
59 | /** |
||
60 | * An extra message to the other platform. |
||
61 | * |
||
62 | * @var |
||
63 | */ |
||
64 | protected $extraMessage; |
||
65 | |||
66 | /** |
||
67 | * @param string $body |
||
68 | * |
||
69 | * @return static |
||
70 | */ |
||
71 | 1 | public static function create($body = '') |
|
75 | |||
76 | /** |
||
77 | * @param string $body |
||
78 | */ |
||
79 | 14 | public function __construct($body = '') |
|
83 | |||
84 | /** |
||
85 | * Set the platform [iOS/Android]. |
||
86 | * |
||
87 | * @param string $platform |
||
88 | * |
||
89 | * @return $this |
||
90 | * |
||
91 | * @throws \NotificationChannels\PusherPushNotifications\Exceptions\CouldNotCreateMessage |
||
92 | */ |
||
93 | 1 | public function platform($platform) |
|
103 | |||
104 | /** |
||
105 | * Set the platform to iOS. |
||
106 | * |
||
107 | * @return $this |
||
108 | */ |
||
109 | 2 | public function iOS() |
|
115 | |||
116 | /** |
||
117 | * Set the platform to Android. |
||
118 | * |
||
119 | * @return $this |
||
120 | */ |
||
121 | 2 | public function android() |
|
127 | |||
128 | /** |
||
129 | * Set an extra message to be sent to Android. |
||
130 | * |
||
131 | * @param \NotificationChannels\PusherPushNotifications\PusherMessage $message |
||
132 | * @return $this |
||
133 | */ |
||
134 | 1 | public function withAndroid(PusherMessage $message) |
|
140 | |||
141 | /** |
||
142 | * Set an extra message to be sent to iOS. |
||
143 | * |
||
144 | * @param \NotificationChannels\PusherPushNotifications\PusherMessage $message |
||
145 | * @return $this |
||
146 | */ |
||
147 | public function withiOS(PusherMessage $message) |
||
153 | |||
154 | /** |
||
155 | * Set an extra message to be sent to another platform. |
||
156 | * |
||
157 | * @param \NotificationChannels\PusherPushNotifications\PusherMessage $message |
||
158 | * @return void |
||
159 | * @throws CouldNotCreateMessage |
||
160 | */ |
||
161 | 1 | private function withExtra(PusherMessage $message) |
|
169 | |||
170 | /** |
||
171 | * Set the message title. |
||
172 | * |
||
173 | * @param string $value |
||
174 | * |
||
175 | * @return $this |
||
176 | */ |
||
177 | 1 | public function title($value) |
|
183 | |||
184 | /** |
||
185 | * Set the message body. |
||
186 | * |
||
187 | * @param string $value |
||
188 | * |
||
189 | * @return $this |
||
190 | */ |
||
191 | 1 | public function body($value) |
|
197 | |||
198 | /** |
||
199 | * Set the message sound (Android). |
||
200 | * |
||
201 | * @param string $value |
||
202 | * |
||
203 | * @return $this |
||
204 | */ |
||
205 | 1 | public function sound($value) |
|
211 | |||
212 | /** |
||
213 | * Set the message icon (Android). |
||
214 | * |
||
215 | * @param string $value |
||
216 | * |
||
217 | * @return $this |
||
218 | */ |
||
219 | 1 | public function icon($value) |
|
225 | |||
226 | /** |
||
227 | * Set the message badge (iOS). |
||
228 | * |
||
229 | * @param int $value |
||
230 | * |
||
231 | * @return $this |
||
232 | */ |
||
233 | 1 | public function badge($value) |
|
239 | |||
240 | /** |
||
241 | * @param string $key |
||
242 | * @param mixed $value |
||
243 | * |
||
244 | * @return $this |
||
245 | */ |
||
246 | public function setOption($key, $value) |
||
252 | |||
253 | /** |
||
254 | * Get an array representation of the message. |
||
255 | * |
||
256 | * @return array |
||
257 | */ |
||
258 | 6 | public function toArray() |
|
264 | |||
265 | /** |
||
266 | * Format the message for iOS. |
||
267 | * |
||
268 | * @return array |
||
269 | */ |
||
270 | 12 | public function toiOS() |
|
289 | |||
290 | /** |
||
291 | * Format the message for Android. |
||
292 | * |
||
293 | * @return array |
||
294 | */ |
||
295 | 6 | public function toAndroid() |
|
312 | |||
313 | /** |
||
314 | * Return the current platform. |
||
315 | * |
||
316 | * @return string |
||
317 | */ |
||
318 | 1 | public function getPlatform() |
|
322 | |||
323 | /** |
||
324 | * Format the final Payload. |
||
325 | * |
||
326 | * @param $message |
||
327 | */ |
||
328 | 13 | private function formatMessage(&$message) |
|
338 | } |
||
339 |