1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Apn; |
4
|
|
|
|
5
|
|
|
class ApnMessage |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* The title of the notification. |
9
|
|
|
* |
10
|
|
|
* @var string |
11
|
|
|
*/ |
12
|
|
|
public $title; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The body of the notification. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
public $body; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The badge of the notification. |
23
|
|
|
* |
24
|
|
|
* @var int |
25
|
|
|
*/ |
26
|
|
|
public $badge; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The sound for the notification. |
30
|
|
|
* |
31
|
|
|
* @var string|null |
32
|
|
|
*/ |
33
|
|
|
public $sound; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The category for action button. |
37
|
|
|
* |
38
|
|
|
* @var string|null |
39
|
|
|
* */ |
40
|
|
|
public $category; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Value indicating incoming resource in the notification. |
44
|
|
|
* |
45
|
|
|
* @var int|null |
46
|
|
|
*/ |
47
|
|
|
public $contentAvailable = null; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Additional data of the notification. |
51
|
|
|
* |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
public $custom = []; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Url arguments of the notification. |
58
|
|
|
* |
59
|
|
|
* @var array |
60
|
|
|
*/ |
61
|
|
|
public $urlArguments = []; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Message specific credentials. |
65
|
|
|
* |
66
|
|
|
* @var ApnCredentials |
67
|
|
|
*/ |
68
|
|
|
public $credentials = null; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string|null $title |
72
|
|
|
* @param string|null $body |
73
|
|
|
* @param array $custom |
74
|
|
|
* @param null|int $badge |
75
|
|
|
* |
76
|
|
|
* @return static |
77
|
|
|
*/ |
78
|
1 |
|
public static function create($title = null, $body = null, $custom = [], $badge = null) |
79
|
|
|
{ |
80
|
1 |
|
return new static($title, $body, $custom, $badge); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string|null $title |
85
|
|
|
* @param string|null $body |
86
|
|
|
* @param array $custom |
87
|
|
|
* @param null|int $badge |
88
|
|
|
*/ |
89
|
15 |
|
public function __construct($title = null, $body = null, $custom = [], $badge = null) |
90
|
|
|
{ |
91
|
15 |
|
$this->title = $title; |
92
|
15 |
|
$this->body = $body; |
93
|
15 |
|
$this->custom = $custom; |
94
|
15 |
|
$this->badge = $badge; |
95
|
15 |
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Set the alert title of the notification. |
99
|
|
|
* |
100
|
|
|
* @param string $title |
101
|
|
|
* |
102
|
|
|
* @return $this |
103
|
|
|
*/ |
104
|
1 |
|
public function title($title) |
105
|
|
|
{ |
106
|
1 |
|
$this->title = $title; |
107
|
|
|
|
108
|
1 |
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Set the alert message of the notification. |
113
|
|
|
* |
114
|
|
|
* @param string $body |
115
|
|
|
* |
116
|
|
|
* @return $this |
117
|
|
|
*/ |
118
|
1 |
|
public function body($body) |
119
|
|
|
{ |
120
|
1 |
|
$this->body = $body; |
121
|
|
|
|
122
|
1 |
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Set the badge of the notification. |
127
|
|
|
* |
128
|
|
|
* @param int $badge |
129
|
|
|
* |
130
|
|
|
* @return $this |
131
|
|
|
*/ |
132
|
1 |
|
public function badge($badge) |
133
|
|
|
{ |
134
|
1 |
|
$this->badge = $badge; |
135
|
|
|
|
136
|
1 |
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Set the sound for the notification. |
141
|
|
|
* |
142
|
|
|
* @param string|null $sound |
143
|
|
|
* |
144
|
|
|
* @return $this |
145
|
|
|
*/ |
146
|
2 |
|
public function sound($sound = 'default') |
147
|
|
|
{ |
148
|
2 |
|
$this->sound = $sound; |
149
|
|
|
|
150
|
2 |
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Set category for this notification. |
155
|
|
|
* |
156
|
|
|
* @param string|null $category |
157
|
|
|
* |
158
|
|
|
* @return $this |
159
|
|
|
* */ |
160
|
1 |
|
public function category($category) |
161
|
|
|
{ |
162
|
1 |
|
$this->category = $category; |
163
|
|
|
|
164
|
1 |
|
return $this; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Set content available value for this notification. |
169
|
|
|
* |
170
|
|
|
* @param int $value |
171
|
|
|
* |
172
|
|
|
* @return $this |
173
|
|
|
*/ |
174
|
1 |
|
public function contentAvailable($value = 1) |
175
|
|
|
{ |
176
|
1 |
|
$this->contentAvailable = $value; |
177
|
|
|
|
178
|
1 |
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Add custom data to the notification. |
183
|
|
|
* |
184
|
|
|
* @param string $key |
185
|
|
|
* @param mixed $value |
186
|
|
|
* |
187
|
|
|
* @return $this |
188
|
|
|
*/ |
189
|
2 |
|
public function custom($key, $value) |
190
|
|
|
{ |
191
|
2 |
|
$this->custom[$key] = $value; |
192
|
|
|
|
193
|
2 |
|
return $this; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Override the data of the notification. |
198
|
|
|
* |
199
|
|
|
* @param array $custom |
200
|
|
|
* |
201
|
|
|
* @return $this |
202
|
|
|
*/ |
203
|
1 |
|
public function setCustom($custom) |
204
|
|
|
{ |
205
|
1 |
|
$this->custom = $custom; |
206
|
|
|
|
207
|
1 |
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Add a url argument to the notification. |
212
|
|
|
* |
213
|
|
|
* @param string $key |
214
|
|
|
* @param mixed $value |
215
|
|
|
* |
216
|
|
|
* @return $this |
217
|
|
|
*/ |
218
|
1 |
|
public function urlArgument($key, $value) |
219
|
|
|
{ |
220
|
1 |
|
$this->urlArguments[$key] = $value; |
221
|
|
|
|
222
|
1 |
|
return $this; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Override the data of the notification. |
227
|
|
|
* |
228
|
|
|
* @param array $urlArguments |
229
|
|
|
* |
230
|
|
|
* @return $this |
231
|
|
|
*/ |
232
|
1 |
|
public function setUrlArguments($urlArguments) |
233
|
|
|
{ |
234
|
1 |
|
$this->urlArguments = $urlArguments; |
235
|
|
|
|
236
|
1 |
|
return $this; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Add an action to the notification. |
241
|
|
|
* |
242
|
|
|
* @param string $action |
243
|
|
|
* @param mixed $params |
244
|
|
|
* |
245
|
|
|
* @return $this |
246
|
|
|
*/ |
247
|
1 |
|
public function action($action, $params = null) |
248
|
|
|
{ |
249
|
1 |
|
return $this->custom('action', [ |
250
|
1 |
|
'action' => $action, |
251
|
1 |
|
'params' => $params, |
252
|
|
|
]); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Set message specific credentials. |
257
|
|
|
* |
258
|
|
|
* @param \NotificationChannels\Apn\ApnCredentials $credentials |
259
|
|
|
* @return $this |
260
|
|
|
*/ |
261
|
|
|
public function credentials(ApnCredentials $credentials) |
262
|
|
|
{ |
263
|
|
|
$this->credentials = $credentials; |
264
|
|
|
|
265
|
|
|
return $this; |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
|