1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the AppleApnPush package |
7
|
|
|
* |
8
|
|
|
* (c) Vitaliy Zhuk <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Apple\ApnPush\Model; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Send this notification to device. |
18
|
|
|
*/ |
19
|
|
|
class Notification |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var Payload |
23
|
|
|
*/ |
24
|
|
|
private $payload; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var ApnId |
28
|
|
|
*/ |
29
|
|
|
private $apnId; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Priority |
33
|
|
|
*/ |
34
|
|
|
private $priority; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Expiration |
38
|
|
|
*/ |
39
|
|
|
private $expiration; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var CollapseId |
43
|
|
|
*/ |
44
|
|
|
private $collapseId; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var PushType |
48
|
|
|
*/ |
49
|
|
|
private $pushType; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Constructor. |
53
|
|
|
* |
54
|
|
|
* @param Payload $payload |
55
|
|
|
* @param ApnId|null $apnId |
56
|
|
|
* @param Priority|null $priority |
57
|
|
|
* @param Expiration|null $expiration |
58
|
|
|
* @param CollapseId|null $collapseId |
59
|
|
|
* @param PushType|null $pushType |
60
|
|
|
*/ |
61
|
|
|
public function __construct(Payload $payload, ?ApnId $apnId = null, ?Priority $priority = null, ?Expiration $expiration = null, ?CollapseId $collapseId = null, ?PushType $pushType = null) |
62
|
|
|
{ |
63
|
|
|
$this->payload = $payload; |
64
|
|
|
$this->priority = $priority; |
65
|
|
|
$this->apnId = $apnId; |
66
|
|
|
$this->expiration = $expiration; |
67
|
|
|
$this->collapseId = $collapseId; |
68
|
|
|
$this->pushType = $pushType; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Create new notification with body only |
73
|
|
|
* |
74
|
|
|
* @param string $body |
75
|
|
|
* |
76
|
|
|
* @return Notification |
77
|
|
|
*/ |
78
|
|
|
public static function createWithBody(string $body): Notification |
79
|
|
|
{ |
80
|
|
|
return new self(Payload::createWithBody($body)); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Set payload |
85
|
|
|
* |
86
|
|
|
* @param Payload $payload |
87
|
|
|
* |
88
|
|
|
* @return Notification |
89
|
|
|
*/ |
90
|
|
|
public function withPayload(Payload $payload): Notification |
91
|
|
|
{ |
92
|
|
|
$cloned = clone $this; |
93
|
|
|
|
94
|
|
|
$cloned->payload = $payload; |
95
|
|
|
|
96
|
|
|
return $cloned; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get payload |
101
|
|
|
* |
102
|
|
|
* @return Payload |
103
|
|
|
*/ |
104
|
|
|
public function getPayload(): Payload |
105
|
|
|
{ |
106
|
|
|
return $this->payload; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Set apn identifier |
111
|
|
|
* |
112
|
|
|
* @param ApnId $apnId |
113
|
|
|
* |
114
|
|
|
* @return Notification |
115
|
|
|
*/ |
116
|
|
|
public function withApnId(ApnId $apnId = null): Notification |
117
|
|
|
{ |
118
|
|
|
$cloned = clone $this; |
119
|
|
|
|
120
|
|
|
$cloned->apnId = $apnId; |
121
|
|
|
|
122
|
|
|
return $cloned; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Get identifier of notification |
127
|
|
|
* |
128
|
|
|
* @return ApnId |
129
|
|
|
*/ |
130
|
|
|
public function getApnId(): ?ApnId |
131
|
|
|
{ |
132
|
|
|
return $this->apnId; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Set priority |
137
|
|
|
* |
138
|
|
|
* @param Priority $priority |
139
|
|
|
* |
140
|
|
|
* @return Notification |
141
|
|
|
*/ |
142
|
|
|
public function withPriority(Priority $priority = null): Notification |
143
|
|
|
{ |
144
|
|
|
$cloned = clone $this; |
145
|
|
|
|
146
|
|
|
$cloned->priority = $priority; |
147
|
|
|
|
148
|
|
|
return $cloned; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Get priority |
153
|
|
|
* |
154
|
|
|
* @return Priority |
155
|
|
|
*/ |
156
|
|
|
public function getPriority(): ?Priority |
157
|
|
|
{ |
158
|
|
|
return $this->priority; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Set expiration |
163
|
|
|
* |
164
|
|
|
* @param Expiration $expiration |
165
|
|
|
* |
166
|
|
|
* @return Notification |
167
|
|
|
*/ |
168
|
|
|
public function withExpiration(Expiration $expiration = null): Notification |
169
|
|
|
{ |
170
|
|
|
$cloned = clone $this; |
171
|
|
|
|
172
|
|
|
$cloned->expiration = $expiration; |
173
|
|
|
|
174
|
|
|
return $cloned; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Get expiration |
179
|
|
|
* |
180
|
|
|
* @return Expiration |
181
|
|
|
*/ |
182
|
|
|
public function getExpiration(): ?Expiration |
183
|
|
|
{ |
184
|
|
|
return $this->expiration; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Set the collapse identifier |
189
|
|
|
* |
190
|
|
|
* @param CollapseId|null $collapseId |
191
|
|
|
* |
192
|
|
|
* @return Notification |
193
|
|
|
*/ |
194
|
|
|
public function withCollapseId(CollapseId $collapseId = null): Notification |
195
|
|
|
{ |
196
|
|
|
$cloned = clone $this; |
197
|
|
|
|
198
|
|
|
$cloned->collapseId = $collapseId; |
199
|
|
|
|
200
|
|
|
return $cloned; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Get the collapse identifier |
205
|
|
|
* |
206
|
|
|
* @return CollapseId|null |
207
|
|
|
*/ |
208
|
|
|
public function getCollapseId(): ?CollapseId |
209
|
|
|
{ |
210
|
|
|
return $this->collapseId; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Set the push type |
215
|
|
|
* |
216
|
|
|
* @param PushType|null $pushType |
217
|
|
|
* |
218
|
|
|
* @return Notification |
219
|
|
|
*/ |
220
|
|
|
public function withPushType(?PushType $pushType): Notification |
221
|
|
|
{ |
222
|
|
|
$cloned = clone $this; |
223
|
|
|
|
224
|
|
|
$cloned->pushType = $pushType; |
225
|
|
|
|
226
|
|
|
return $cloned; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Get the push type |
231
|
|
|
* |
232
|
|
|
* @return PushType|null |
233
|
|
|
*/ |
234
|
|
|
public function getPushType(): ?PushType |
235
|
|
|
{ |
236
|
|
|
return $this->pushType; |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|