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
|
1 |
|
public static function create($title = null, $body = null, $custom = [], $badge = null) |
65
|
|
|
{ |
66
|
1 |
|
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
|
13 |
|
public function __construct($title = null, $body = null, $custom = [], $badge = null) |
78
|
|
|
{ |
79
|
13 |
|
$this->title = $title; |
80
|
13 |
|
$this->body = $body; |
81
|
13 |
|
$this->custom = $custom; |
82
|
13 |
|
$this->badge = $badge; |
83
|
13 |
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Set the alert title of the notification. |
87
|
|
|
* |
88
|
|
|
* @param string $title |
89
|
|
|
* |
90
|
|
|
* @return $this |
91
|
|
|
*/ |
92
|
1 |
|
public function title($title) |
93
|
|
|
{ |
94
|
1 |
|
$this->title = $title; |
95
|
|
|
|
96
|
1 |
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Set the alert message of the notification. |
101
|
|
|
* |
102
|
|
|
* @param string $body |
103
|
|
|
* |
104
|
|
|
* @return $this |
105
|
|
|
*/ |
106
|
1 |
|
public function body($body) |
107
|
|
|
{ |
108
|
1 |
|
$this->body = $body; |
109
|
|
|
|
110
|
1 |
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Set the badge of the notification. |
115
|
|
|
* |
116
|
|
|
* @param int $badge |
117
|
|
|
* |
118
|
|
|
* @return $this |
119
|
|
|
*/ |
120
|
1 |
|
public function badge($badge) |
121
|
|
|
{ |
122
|
1 |
|
$this->badge = $badge; |
123
|
|
|
|
124
|
1 |
|
return $this; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Set the sound for the notification. |
129
|
|
|
* |
130
|
|
|
* @param string|null $sound |
131
|
|
|
* |
132
|
|
|
* @return $this |
133
|
|
|
*/ |
134
|
2 |
|
public function sound($sound = 'default') |
135
|
|
|
{ |
136
|
2 |
|
$this->sound = $sound; |
137
|
|
|
|
138
|
2 |
|
return $this; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Set category for this notification. |
143
|
|
|
* |
144
|
|
|
* @param string|null $category |
145
|
|
|
* |
146
|
|
|
* @return $this |
147
|
|
|
* */ |
148
|
1 |
|
public function category($category) |
149
|
|
|
{ |
150
|
1 |
|
$this->category = $category; |
151
|
|
|
|
152
|
1 |
|
return $this; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Set content available value for this notification. |
157
|
|
|
* |
158
|
|
|
* @param int $value |
159
|
|
|
* |
160
|
|
|
* @return $this |
161
|
|
|
*/ |
162
|
1 |
|
public function contentAvailable($value = 1) |
163
|
|
|
{ |
164
|
1 |
|
$this->contentAvailable = $value; |
165
|
|
|
|
166
|
1 |
|
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
|
2 |
|
public function custom($key, $value) |
178
|
|
|
{ |
179
|
2 |
|
$this->custom[$key] = $value; |
180
|
|
|
|
181
|
2 |
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Override the data of the notification. |
186
|
|
|
* |
187
|
|
|
* @param array $custom |
188
|
|
|
* |
189
|
|
|
* @return $this |
190
|
|
|
*/ |
191
|
1 |
|
public function setCustom($custom) |
192
|
|
|
{ |
193
|
1 |
|
$this->custom = $custom; |
194
|
|
|
|
195
|
1 |
|
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
|
1 |
|
public function action($action, $params = null) |
207
|
|
|
{ |
208
|
1 |
|
return $this->custom('action', [ |
209
|
1 |
|
'action' => $action, |
210
|
1 |
|
'params' => $params, |
211
|
|
|
]); |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|
Adding a
@return
annotation 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.