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
|
|
|
* Constructor. |
43
|
|
|
* |
44
|
|
|
* @param Payload $payload |
45
|
|
|
* @param ApnId|null $apnId |
46
|
|
|
* @param Priority|null $priority |
47
|
|
|
* @param Expiration|null $expiration |
48
|
|
|
*/ |
49
|
|
|
public function __construct( |
50
|
|
|
Payload $payload, |
51
|
|
|
ApnId $apnId = null, |
52
|
|
|
Priority $priority = null, |
53
|
|
|
Expiration $expiration = null |
54
|
|
|
) { |
55
|
|
|
$this->payload = $payload; |
56
|
|
|
$this->priority = $priority; |
57
|
|
|
$this->apnId = $apnId; |
58
|
|
|
$this->expiration = $expiration; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Create new notification with body only |
63
|
|
|
* |
64
|
|
|
* @param string $body |
65
|
|
|
* |
66
|
|
|
* @return Notification |
67
|
|
|
*/ |
68
|
|
|
public static function createWithBody(string $body): Notification |
69
|
|
|
{ |
70
|
|
|
return new self(Payload::createWithBody($body)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Set payload |
75
|
|
|
* |
76
|
|
|
* @param Payload $payload |
77
|
|
|
* |
78
|
|
|
* @return Notification |
79
|
|
|
*/ |
80
|
|
|
public function withPayload(Payload $payload): Notification |
81
|
|
|
{ |
82
|
|
|
$cloned = clone $this; |
83
|
|
|
|
84
|
|
|
$cloned->payload = $payload; |
85
|
|
|
|
86
|
|
|
return $cloned; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get payload |
91
|
|
|
* |
92
|
|
|
* @return Payload |
93
|
|
|
*/ |
94
|
|
|
public function getPayload(): Payload |
95
|
|
|
{ |
96
|
|
|
return $this->payload; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Set apn identifier |
101
|
|
|
* |
102
|
|
|
* @param ApnId $apnId |
103
|
|
|
* |
104
|
|
|
* @return Notification |
105
|
|
|
*/ |
106
|
|
|
public function withApnId(ApnId $apnId = null): Notification |
107
|
|
|
{ |
108
|
|
|
$cloned = clone $this; |
109
|
|
|
|
110
|
|
|
$cloned->apnId = $apnId; |
111
|
|
|
|
112
|
|
|
return $cloned; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get identifier of notification |
117
|
|
|
* |
118
|
|
|
* @return ApnId |
119
|
|
|
*/ |
120
|
|
|
public function getApnId(): ?ApnId |
121
|
|
|
{ |
122
|
|
|
return $this->apnId; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Set priority |
127
|
|
|
* |
128
|
|
|
* @param Priority $priority |
129
|
|
|
* |
130
|
|
|
* @return Notification |
131
|
|
|
*/ |
132
|
|
|
public function withPriority(Priority $priority = null): Notification |
133
|
|
|
{ |
134
|
|
|
$cloned = clone $this; |
135
|
|
|
|
136
|
|
|
$cloned->priority = $priority; |
137
|
|
|
|
138
|
|
|
return $cloned; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Get priority |
143
|
|
|
* |
144
|
|
|
* @return Priority |
145
|
|
|
*/ |
146
|
|
|
public function getPriority(): ?Priority |
147
|
|
|
{ |
148
|
|
|
return $this->priority; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Set expiration |
153
|
|
|
* |
154
|
|
|
* @param Expiration $expiration |
155
|
|
|
* |
156
|
|
|
* @return Notification |
157
|
|
|
*/ |
158
|
|
|
public function withExpiration(Expiration $expiration = null): Notification |
159
|
|
|
{ |
160
|
|
|
$cloned = clone $this; |
161
|
|
|
|
162
|
|
|
$cloned->expiration = $expiration; |
163
|
|
|
|
164
|
|
|
return $cloned; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Get expiration |
169
|
|
|
* |
170
|
|
|
* @return Expiration |
171
|
|
|
*/ |
172
|
|
|
public function getExpiration(): ?Expiration |
173
|
|
|
{ |
174
|
|
|
return $this->expiration; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|