1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Fcm; |
4
|
|
|
|
5
|
|
|
class FcmNotification |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var string |
9
|
|
|
*/ |
10
|
|
|
protected $title; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $body; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $clickAction; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $androidChannelId; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $icon; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $sound; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $badge; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $tag; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $color; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
protected $bodyLocKey; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var array |
59
|
|
|
*/ |
60
|
|
|
protected $bodyLocArgs; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
protected $titleLocKey; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var array |
69
|
|
|
*/ |
70
|
|
|
protected $titleLocArgs; |
71
|
|
|
|
72
|
|
|
public static function create() |
73
|
|
|
{ |
74
|
|
|
return new static(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function getTitle() |
81
|
|
|
{ |
82
|
|
|
return $this->title; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* [Optional] The notification's title. |
87
|
|
|
* |
88
|
|
|
* This field is not visible on iOS phones and tablets. |
89
|
|
|
* |
90
|
|
|
* @param string $title |
91
|
|
|
* @return $this |
92
|
|
|
*/ |
93
|
|
|
public function setTitle($title) |
94
|
|
|
{ |
95
|
|
|
$this->title = $title; |
96
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function getBody() |
104
|
|
|
{ |
105
|
|
|
return $this->body; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* [Optional] The notification's body text. |
110
|
|
|
* |
111
|
|
|
* @param string $body |
112
|
|
|
* @return $this |
113
|
|
|
*/ |
114
|
|
|
public function setBody($body) |
115
|
|
|
{ |
116
|
|
|
$this->body = $body; |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function getClickAction() |
125
|
|
|
{ |
126
|
|
|
return $this->clickAction; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* [Optional] |
131
|
|
|
* iOS: |
132
|
|
|
* The action associated with a user click on the notification. |
133
|
|
|
* Corresponds to category in the APNs payload. |
134
|
|
|
* |
135
|
|
|
* Android: |
136
|
|
|
* The action associated with a user click on the notification. |
137
|
|
|
* If specified, an activity with a matching intent filter is launched when a user clicks on the notification. |
138
|
|
|
* |
139
|
|
|
* Web: |
140
|
|
|
* The action associated with a user click on the notification. |
141
|
|
|
* For all URL values, secure HTTPS is required. |
142
|
|
|
* |
143
|
|
|
* @param string $clickAction |
144
|
|
|
* @return $this |
145
|
|
|
*/ |
146
|
|
|
public function setClickAction($clickAction) |
147
|
|
|
{ |
148
|
|
|
$this->clickAction = $clickAction; |
149
|
|
|
|
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return string |
155
|
|
|
*/ |
156
|
|
|
public function getAndroidChannelId() |
157
|
|
|
{ |
158
|
|
|
return $this->androidChannelId; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* [Optional] The notification's channel id (new in Android O). |
163
|
|
|
* The app must create a channel with this ID before any notification with this key is received. |
164
|
|
|
* If you don't send this key in the request, or if the channel id provided has not yet been created by your app, FCM uses the channel id specified in your app |
165
|
|
|
* manifest. |
166
|
|
|
* |
167
|
|
|
* @param string $androidChannelId |
168
|
|
|
* @return $this |
169
|
|
|
*/ |
170
|
|
|
public function setAndroidChannelId($androidChannelId) |
171
|
|
|
{ |
172
|
|
|
$this->androidChannelId = $androidChannelId; |
173
|
|
|
|
174
|
|
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return string |
179
|
|
|
*/ |
180
|
|
|
public function getIcon() |
181
|
|
|
{ |
182
|
|
|
return $this->icon; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* [Optional] The notification's icon. |
187
|
|
|
* Sets the notification icon to myicon for drawable resource myicon. If you don't send this key in the request, FCM displays the launcher icon specified in |
188
|
|
|
* your app manifest. |
189
|
|
|
* |
190
|
|
|
* @param string $icon |
191
|
|
|
* @return $this |
192
|
|
|
*/ |
193
|
|
|
public function setIcon($icon) |
194
|
|
|
{ |
195
|
|
|
$this->icon = $icon; |
196
|
|
|
|
197
|
|
|
return $this; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @return string |
202
|
|
|
*/ |
203
|
|
|
public function getSound() |
204
|
|
|
{ |
205
|
|
|
return $this->sound; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* [Optional] The sound to play when the device receives the notification. |
210
|
|
|
* Supports "default" or the filename of a sound resource bundled in the app. Sound files must reside in /res/raw/. |
211
|
|
|
* |
212
|
|
|
* @param string $sound |
213
|
|
|
* @return $this |
214
|
|
|
*/ |
215
|
|
|
public function setSound($sound) |
216
|
|
|
{ |
217
|
|
|
$this->sound = $sound; |
218
|
|
|
|
219
|
|
|
return $this; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @return string |
224
|
|
|
*/ |
225
|
|
|
public function getBadge() |
226
|
|
|
{ |
227
|
|
|
return $this->badge; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* [Optional] The value of the badge on the home screen app icon. |
232
|
|
|
* If not specified, the badge is not changed. |
233
|
|
|
* If set to 0, the badge is removed. |
234
|
|
|
* |
235
|
|
|
* @param string $badge |
236
|
|
|
* @return $this |
237
|
|
|
*/ |
238
|
|
|
public function setBadge($badge) |
239
|
|
|
{ |
240
|
|
|
$this->badge = $badge; |
241
|
|
|
|
242
|
|
|
return $this; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @return string |
247
|
|
|
*/ |
248
|
|
|
public function getTag() |
249
|
|
|
{ |
250
|
|
|
return $this->tag; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* [Optional] Identifier used to replace existing notifications in the notification drawer. |
255
|
|
|
* If not specified, each request creates a new notification. |
256
|
|
|
* If specified and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer. |
257
|
|
|
* |
258
|
|
|
* @param string $tag |
259
|
|
|
* @return $this |
260
|
|
|
*/ |
261
|
|
|
public function setTag($tag) |
262
|
|
|
{ |
263
|
|
|
$this->tag = $tag; |
264
|
|
|
|
265
|
|
|
return $this; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* @return string |
270
|
|
|
*/ |
271
|
|
|
public function getColor() |
272
|
|
|
{ |
273
|
|
|
return $this->color; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* [Optional] The notification's icon color, expressed in #rrggbb format. |
278
|
|
|
* |
279
|
|
|
* @param string $color |
280
|
|
|
* @return $this |
281
|
|
|
*/ |
282
|
|
|
public function setColor($color) |
283
|
|
|
{ |
284
|
|
|
$this->color = $color; |
285
|
|
|
|
286
|
|
|
return $this; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* @return string |
291
|
|
|
*/ |
292
|
|
|
public function getBodyLocKey() |
293
|
|
|
{ |
294
|
|
|
return $this->bodyLocKey; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* [Optional] The key to the body string in the app's string resources to use to localize the body text to the user's current localization. |
299
|
|
|
* |
300
|
|
|
* @param string $bodyLocKey |
301
|
|
|
* @return $this |
302
|
|
|
*/ |
303
|
|
|
public function setBodyLocKey($bodyLocKey) |
304
|
|
|
{ |
305
|
|
|
$this->bodyLocKey = $bodyLocKey; |
306
|
|
|
|
307
|
|
|
return $this; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @return array |
312
|
|
|
*/ |
313
|
|
|
public function getBodyLocArgs() |
314
|
|
|
{ |
315
|
|
|
return $this->bodyLocArgs; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* [Optional] The key to the title string in the app's string resources to use to localize the title text to the user's current localization. |
320
|
|
|
* |
321
|
|
|
* @param array $bodyLocArgs |
322
|
|
|
* @return $this |
323
|
|
|
*/ |
324
|
|
|
public function setBodyLocArgs($bodyLocArgs) |
325
|
|
|
{ |
326
|
|
|
$this->bodyLocArgs = $bodyLocArgs; |
327
|
|
|
|
328
|
|
|
return $this; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @return string |
333
|
|
|
*/ |
334
|
|
|
public function getTitleLocKey() |
335
|
|
|
{ |
336
|
|
|
return $this->titleLocKey; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* [Optional] Variable string values to be used in place of the format specifiers in body_loc_key to use to localize the body text to the user's current |
341
|
|
|
* localization. |
342
|
|
|
* |
343
|
|
|
* @param string $titleLocKey |
344
|
|
|
* @return $this |
345
|
|
|
*/ |
346
|
|
|
public function setTitleLocKey($titleLocKey) |
347
|
|
|
{ |
348
|
|
|
$this->titleLocKey = $titleLocKey; |
349
|
|
|
|
350
|
|
|
return $this; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* @return array |
355
|
|
|
*/ |
356
|
|
|
public function getTitleLocArgs() |
357
|
|
|
{ |
358
|
|
|
return $this->titleLocArgs; |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* [Optional] Variable string values to be used in place of the format specifiers in title_loc_key to use to localize the title text to the user's current |
363
|
|
|
* localization. |
364
|
|
|
* |
365
|
|
|
* @param array $titleLocArgs |
366
|
|
|
* @return $this |
367
|
|
|
*/ |
368
|
|
|
public function setTitleLocArgs($titleLocArgs) |
369
|
|
|
{ |
370
|
|
|
$this->titleLocArgs = $titleLocArgs; |
371
|
|
|
|
372
|
|
|
return $this; |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* @return array |
377
|
|
|
*/ |
378
|
|
|
public function toArray() |
379
|
|
|
{ |
380
|
|
|
return [ |
381
|
|
|
'title' => $this->title, |
382
|
|
|
'body' => $this->body, |
383
|
|
|
'click_action' => $this->clickAction, |
384
|
|
|
'badge' => $this->badge, |
385
|
|
|
'android_channel_id' => $this->androidChannelId, |
386
|
|
|
'icon' => $this->icon, |
387
|
|
|
'sound' => $this->sound, |
388
|
|
|
'tag' => $this->tag, |
389
|
|
|
'color' => $this->color, |
390
|
|
|
'body_loc_key' => $this->bodyLocKey, |
391
|
|
|
'body_loc_args' => $this->bodyLocArgs, |
392
|
|
|
'title_loc_key' => $this->titleLocKey, |
393
|
|
|
'title_loc_args' => $this->titleLocArgs, |
394
|
|
|
]; |
395
|
|
|
} |
396
|
|
|
} |
397
|
|
|
|