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