|
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
|
|
|
* @param string|null $title |
|
58
|
|
|
* @param string|null $body |
|
59
|
|
|
* @param array $custom |
|
60
|
|
|
* @param null|int $badge |
|
61
|
|
|
* |
|
62
|
|
|
* @return static |
|
63
|
|
|
*/ |
|
64
|
|
|
public static function create($title = null, $body = null, $custom = [], $badge = null) |
|
65
|
|
|
{ |
|
66
|
|
|
return new static($title, $body, $custom, $badge); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param string|null $title |
|
71
|
|
|
* @param string|null $body |
|
72
|
|
|
* @param array $custom |
|
73
|
|
|
* @param null|int $badge |
|
74
|
|
|
* |
|
75
|
|
|
* @return static |
|
|
|
|
|
|
76
|
|
|
*/ |
|
77
|
1 |
|
public function __construct($title = null, $body = null, $custom = [], $badge = null) |
|
78
|
|
|
{ |
|
79
|
1 |
|
$this->title = $title; |
|
80
|
1 |
|
$this->body = $body; |
|
81
|
1 |
|
$this->custom = $custom; |
|
82
|
1 |
|
$this->badge = $badge; |
|
83
|
1 |
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Set the alert title of the notification. |
|
87
|
|
|
* |
|
88
|
|
|
* @param string $title |
|
89
|
|
|
* |
|
90
|
|
|
* @return $this |
|
91
|
|
|
*/ |
|
92
|
|
|
public function title($title) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->title = $title; |
|
95
|
|
|
|
|
96
|
|
|
return $this; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Set the alert message of the notification. |
|
101
|
|
|
* |
|
102
|
|
|
* @param string $body |
|
103
|
|
|
* |
|
104
|
|
|
* @return $this |
|
105
|
|
|
*/ |
|
106
|
|
|
public function body($body) |
|
107
|
|
|
{ |
|
108
|
|
|
$this->body = $body; |
|
109
|
|
|
|
|
110
|
|
|
return $this; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Set the badge of the notification. |
|
115
|
|
|
* |
|
116
|
|
|
* @param int $badge |
|
117
|
|
|
* |
|
118
|
|
|
* @return $this |
|
119
|
|
|
*/ |
|
120
|
|
|
public function badge($badge) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->badge = $badge; |
|
123
|
|
|
|
|
124
|
|
|
return $this; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Set the sound for the notification. |
|
129
|
|
|
* |
|
130
|
|
|
* @param string|null $sound |
|
131
|
|
|
* |
|
132
|
|
|
* @return $this |
|
133
|
|
|
*/ |
|
134
|
|
|
public function sound($sound = 'default') |
|
135
|
|
|
{ |
|
136
|
|
|
$this->sound = $sound; |
|
137
|
|
|
|
|
138
|
|
|
return $this; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Set category for this notification. |
|
143
|
|
|
* |
|
144
|
|
|
* @param string|null $category |
|
145
|
|
|
* |
|
146
|
|
|
* @return $this |
|
147
|
|
|
* */ |
|
148
|
|
|
public function category($category) |
|
149
|
|
|
{ |
|
150
|
|
|
$this->category = $category; |
|
151
|
|
|
|
|
152
|
|
|
return $this; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Set content available value for this notification. |
|
157
|
|
|
* |
|
158
|
|
|
* @param int $value |
|
159
|
|
|
* |
|
160
|
|
|
* @return $this |
|
161
|
|
|
*/ |
|
162
|
|
|
public function contentAvailable($value = 1) |
|
163
|
|
|
{ |
|
164
|
|
|
$this->contentAvailable = $value; |
|
165
|
|
|
|
|
166
|
|
|
return $this; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Add custom data to the notification. |
|
171
|
|
|
* |
|
172
|
|
|
* @param string $key |
|
173
|
|
|
* @param mixed $value |
|
174
|
|
|
* |
|
175
|
|
|
* @return $this |
|
176
|
|
|
*/ |
|
177
|
|
|
public function custom($key, $value) |
|
178
|
|
|
{ |
|
179
|
|
|
$this->custom[$key] = $value; |
|
180
|
|
|
|
|
181
|
|
|
return $this; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Override the data of the notification. |
|
186
|
|
|
* |
|
187
|
|
|
* @param array $custom |
|
188
|
|
|
* |
|
189
|
|
|
* @return $this |
|
190
|
|
|
*/ |
|
191
|
|
|
public function setCustom($custom) |
|
192
|
|
|
{ |
|
193
|
|
|
$this->custom = $custom; |
|
194
|
|
|
|
|
195
|
|
|
return $this; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Add an action to the notification. |
|
200
|
|
|
* |
|
201
|
|
|
* @param string $action |
|
202
|
|
|
* @param mixed $params |
|
203
|
|
|
* |
|
204
|
|
|
* @return $this |
|
205
|
|
|
*/ |
|
206
|
|
|
public function action($action, $params = null) |
|
207
|
|
|
{ |
|
208
|
|
|
return $this->custom('action', [ |
|
209
|
|
|
'action' => $action, |
|
210
|
|
|
'params' => $params, |
|
211
|
|
|
]); |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.