1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Gcm; |
4
|
|
|
|
5
|
|
|
class GcmMessage |
6
|
|
|
{ |
7
|
|
|
const PRIORITY_NORMAL = 'normal'; |
8
|
|
|
const PRIORITY_HIGH = 'high'; |
9
|
|
|
|
10
|
|
|
const DEFAULT_SOUND = 'default'; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* The title of the notification. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
public $title; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The message of the notification. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
public $message; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The badge of the notification. |
28
|
|
|
* @warning UNUSED |
29
|
|
|
* |
30
|
|
|
* @var int |
31
|
|
|
*/ |
32
|
|
|
public $badge; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The priority of the notification. |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
public $priority = self::PRIORITY_NORMAL; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Notification sound. |
43
|
|
|
* |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
public $sound = self::DEFAULT_SOUND; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Additional data of the notification. |
50
|
|
|
* |
51
|
|
|
* @var array |
52
|
|
|
*/ |
53
|
|
|
public $data = []; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Additional notification data of the notification. |
57
|
|
|
* |
58
|
|
|
* @var array |
59
|
|
|
*/ |
60
|
|
|
public $notification = []; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string|null $title |
64
|
|
|
* @param string|null $message |
65
|
|
|
* @param array $data |
66
|
|
|
* @param string $priority |
67
|
|
|
* |
68
|
|
|
* @return static |
69
|
|
|
*/ |
70
|
1 |
|
public static function create($title = null, $message = null, $data = [], $notification = [], $priority = self::PRIORITY_NORMAL, $sound = self::DEFAULT_SOUND) |
71
|
|
|
{ |
72
|
1 |
|
return new static($title, $message, $data, $notification, $priority, $sound); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string|null $title |
77
|
|
|
* @param string|null $message |
78
|
|
|
* @param array $data |
79
|
|
|
* @param string $priority |
80
|
|
|
* @param string $sound |
81
|
|
|
*/ |
82
|
11 |
|
public function __construct($title = null, $message = null, $data = [], $notification = [], $priority = self::PRIORITY_NORMAL, $sound = self::DEFAULT_SOUND) |
83
|
|
|
{ |
84
|
11 |
|
$this->title = $title; |
85
|
11 |
|
$this->message = $message; |
86
|
11 |
|
$this->data = $data; |
87
|
11 |
|
$this->notification = $notification; |
88
|
11 |
|
$this->priority = $priority; |
89
|
11 |
|
$this->sound = $sound; |
90
|
11 |
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Set the title of the notification. |
94
|
|
|
* |
95
|
|
|
* @param string $title |
96
|
|
|
* |
97
|
|
|
* @return $this |
98
|
|
|
*/ |
99
|
1 |
|
public function title($title) |
100
|
|
|
{ |
101
|
1 |
|
$this->title = $title; |
102
|
|
|
|
103
|
1 |
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Set the message of the notification. |
108
|
|
|
* |
109
|
|
|
* @param string $message |
110
|
|
|
* |
111
|
|
|
* @return $this |
112
|
|
|
*/ |
113
|
1 |
|
public function message($message) |
114
|
|
|
{ |
115
|
1 |
|
$this->message = $message; |
116
|
|
|
|
117
|
1 |
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Set the badge of the notification. |
122
|
|
|
* |
123
|
|
|
* @param int $badge |
124
|
|
|
* |
125
|
|
|
* @return $this |
126
|
|
|
*/ |
127
|
|
|
public function badge($badge) |
128
|
|
|
{ |
129
|
|
|
$this->badge = $badge; |
130
|
|
|
|
131
|
|
|
return $this; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Set the priority of the notification. |
136
|
|
|
* |
137
|
|
|
* @param string $priority |
138
|
|
|
* |
139
|
|
|
* @return $this |
140
|
|
|
*/ |
141
|
1 |
|
public function priority($priority) |
142
|
|
|
{ |
143
|
1 |
|
$this->priority = $priority; |
144
|
|
|
|
145
|
1 |
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Set the sound for notification. |
150
|
|
|
* |
151
|
|
|
* @param string $sound |
152
|
|
|
* |
153
|
|
|
* @return $this |
154
|
|
|
*/ |
155
|
1 |
|
public function sound($sound) |
156
|
|
|
{ |
157
|
1 |
|
$this->sound = $sound; |
158
|
|
|
|
159
|
1 |
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Add data to the notification. |
164
|
|
|
* |
165
|
|
|
* @param string $key |
166
|
|
|
* @param mixed $value |
167
|
|
|
* |
168
|
|
|
* @return $this |
169
|
|
|
*/ |
170
|
1 |
|
public function data($key, $value) |
171
|
|
|
{ |
172
|
1 |
|
$this->data[$key] = $value; |
173
|
|
|
|
174
|
1 |
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Override the data of the notification. |
179
|
|
|
* |
180
|
|
|
* @param array $data |
181
|
|
|
* @return $this |
182
|
|
|
*/ |
183
|
|
|
public function setData($data) |
184
|
|
|
{ |
185
|
|
|
$this->data = $data; |
186
|
|
|
|
187
|
|
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Add notification data to the notification. |
192
|
|
|
* |
193
|
|
|
* @param string $key |
194
|
|
|
* @param mixed $value |
195
|
|
|
* |
196
|
|
|
* @return $this |
197
|
|
|
*/ |
198
|
1 |
|
public function notification($key, $value) |
199
|
|
|
{ |
200
|
1 |
|
$this->notification[$key] = $value; |
201
|
|
|
|
202
|
1 |
|
return $this; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Override the notification data of the notification. |
207
|
|
|
* |
208
|
|
|
* @param array $notification |
209
|
|
|
* @return $this |
210
|
|
|
*/ |
211
|
|
|
public function setNotification($notification) |
212
|
|
|
{ |
213
|
|
|
$this->notification = $notification; |
214
|
|
|
|
215
|
|
|
return $this; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Add an action to the notification. |
220
|
|
|
* |
221
|
|
|
* @param string $action |
222
|
|
|
* @param mixed $params |
223
|
|
|
* |
224
|
|
|
* @return $this |
225
|
|
|
*/ |
226
|
|
|
public function action($action, $params = null) |
227
|
|
|
{ |
228
|
|
|
return $this->data('action', [ |
229
|
|
|
'action' => $action, |
230
|
|
|
'params' => $params, |
231
|
|
|
]); |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
|