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