1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\IonicPushNotifications; |
4
|
|
|
|
5
|
|
|
class IonicPushMessage |
6
|
|
|
{ |
7
|
|
|
/** @var string */ |
8
|
|
|
public $sendTo = 'tokens'; |
9
|
|
|
|
10
|
|
|
/** @var string */ |
11
|
|
|
public $profile; |
12
|
|
|
|
13
|
|
|
/** @var string */ |
14
|
|
|
public $title = ''; |
15
|
|
|
|
16
|
|
|
/** @var string */ |
17
|
|
|
public $message = ''; |
18
|
|
|
|
19
|
|
|
/** @var string */ |
20
|
|
|
public $sound = ''; |
21
|
|
|
|
22
|
|
|
/** @var array */ |
23
|
|
|
public $payload = []; |
24
|
|
|
|
25
|
|
|
/** @var array */ |
26
|
|
|
public $iosData = []; |
27
|
|
|
|
28
|
|
|
/** @var array */ |
29
|
|
|
public $androidData = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param array $data |
|
|
|
|
33
|
|
|
* |
34
|
|
|
* @return static |
35
|
|
|
*/ |
36
|
3 |
|
public static function create($profile) |
37
|
|
|
{ |
38
|
3 |
|
return new static($profile); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $profile |
43
|
|
|
*/ |
44
|
11 |
|
public function __construct($profile) |
45
|
|
|
{ |
46
|
11 |
|
$this->profile = $profile; |
47
|
11 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Set the method of targeting users - tokens (default), user_ids, or emails. |
51
|
|
|
* |
52
|
|
|
* @param string $profile |
|
|
|
|
53
|
|
|
* |
54
|
|
|
* @return $this |
55
|
|
|
*/ |
56
|
|
|
public function sendTo($sendTo) |
57
|
|
|
{ |
58
|
|
|
$this->sendTo = $sendTo; |
59
|
|
|
|
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Set the title. |
65
|
|
|
* |
66
|
|
|
* @param string $title |
67
|
|
|
* |
68
|
|
|
* @return $this |
69
|
|
|
*/ |
70
|
1 |
|
public function title($title) |
71
|
|
|
{ |
72
|
1 |
|
$this->title = $title; |
73
|
|
|
|
74
|
1 |
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Set the message. |
79
|
|
|
* |
80
|
|
|
* @param string $message |
81
|
|
|
* |
82
|
|
|
* @return $this |
83
|
|
|
*/ |
84
|
3 |
|
public function message($message) |
85
|
|
|
{ |
86
|
3 |
|
$this->message = $message; |
87
|
|
|
|
88
|
3 |
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Set the security sound to use. |
93
|
|
|
* |
94
|
|
|
* @param string $sound |
95
|
|
|
* |
96
|
|
|
* @return $this |
97
|
|
|
*/ |
98
|
|
|
public function sound($sound) |
99
|
|
|
{ |
100
|
|
|
$this->sound = $sound; |
101
|
|
|
|
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Send custom key/value data with your notifications. |
107
|
|
|
* |
108
|
|
|
* @param array $payload |
109
|
|
|
* |
110
|
|
|
* @return $this |
111
|
|
|
*/ |
112
|
|
|
public function payload($payload) |
113
|
|
|
{ |
114
|
|
|
$this->payload = $payload; |
115
|
|
|
|
116
|
|
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Dynamically add device specific data. |
121
|
|
|
* |
122
|
|
|
* @param string $method |
123
|
|
|
* @param array $args |
124
|
|
|
* |
125
|
|
|
* @return object |
126
|
|
|
*/ |
127
|
6 |
|
public function __call($method, $args) |
128
|
|
|
{ |
129
|
6 |
|
if (substr($method, 0, 3) == 'ios') { |
130
|
5 |
|
$key = snake_case(substr($method, 3)); |
131
|
|
|
|
132
|
5 |
|
if (in_array($key, $this->allowediOSOptions())) { |
133
|
4 |
|
$this->iosData[$key] = $args[0]; |
134
|
4 |
|
} |
135
|
6 |
|
} elseif (substr($method, 0, 7) == 'android') { |
136
|
1 |
|
$key = snake_case(substr($method, 7)); |
137
|
|
|
|
138
|
1 |
|
if (in_array($key, $this->allowedAndroidOptions())) { |
139
|
1 |
|
$this->androidData[$key] = $args[0]; |
140
|
1 |
|
} |
141
|
1 |
|
} |
142
|
|
|
|
143
|
6 |
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Get the method we want to use to send messages. |
148
|
|
|
* |
149
|
|
|
* @return string |
150
|
|
|
*/ |
151
|
3 |
|
public function getSendToType() |
152
|
|
|
{ |
153
|
3 |
|
return $this->sendTo; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* List of allowed Android options. |
158
|
|
|
* |
159
|
|
|
* @return array |
160
|
|
|
*/ |
161
|
1 |
|
public function allowedAndroidOptions() |
162
|
|
|
{ |
163
|
|
|
return [ |
164
|
1 |
|
'collapse_key', |
165
|
1 |
|
'content_available', |
166
|
1 |
|
'data', |
167
|
1 |
|
'delay_while_idle', |
168
|
1 |
|
'icon', |
169
|
1 |
|
'icon_color', |
170
|
1 |
|
'message', |
171
|
1 |
|
'priortiy', |
172
|
1 |
|
'sound', |
173
|
1 |
|
'tag', |
174
|
1 |
|
'time_to_live', |
175
|
1 |
|
'title', |
176
|
1 |
|
]; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* List of allowed iOS options. |
181
|
|
|
* |
182
|
|
|
* @return array |
183
|
|
|
*/ |
184
|
5 |
|
public function allowediOSOptions() |
185
|
|
|
{ |
186
|
|
|
return [ |
187
|
5 |
|
'message', |
188
|
5 |
|
'title', |
189
|
5 |
|
'badge', |
190
|
5 |
|
'payload', |
191
|
5 |
|
'sound', |
192
|
5 |
|
'priortiy', |
193
|
5 |
|
'expire', |
194
|
5 |
|
'content_available', |
195
|
5 |
|
]; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @return array |
200
|
|
|
*/ |
201
|
10 |
|
public function toArray() |
202
|
|
|
{ |
203
|
|
|
$data = [ |
204
|
10 |
|
'profile' => $this->profile, |
205
|
|
|
'notification' => [ |
206
|
10 |
|
'message' => $this->message, |
207
|
10 |
|
], |
208
|
10 |
|
]; |
209
|
|
|
|
210
|
10 |
|
if (! empty($this->title)) { |
211
|
1 |
|
$data['notification']['title'] = $this->title; |
212
|
1 |
|
} |
213
|
|
|
|
214
|
10 |
|
if (! empty($this->sound)) { |
215
|
|
|
$data['notification']['sound'] = $this->sound; |
216
|
|
|
} |
217
|
|
|
|
218
|
10 |
|
if (! empty($this->iosData)) { |
219
|
4 |
|
$data['notification']['ios'] = $this->iosData; |
220
|
4 |
|
} |
221
|
|
|
|
222
|
10 |
|
if (! empty($this->androidData)) { |
223
|
1 |
|
$data['notification']['android'] = $this->androidData; |
224
|
1 |
|
} |
225
|
|
|
|
226
|
10 |
|
if (! empty($this->payload)) { |
227
|
|
|
$data['notification']['payload'] = $this->payload; |
228
|
|
|
} |
229
|
|
|
|
230
|
10 |
|
return $data; |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.