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
|
|
|
* Value object for alert object |
18
|
|
|
*/ |
19
|
|
|
class Alert |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $title; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var Localized |
28
|
|
|
*/ |
29
|
|
|
private $titleLocalized; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private $body; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Localized |
38
|
|
|
*/ |
39
|
|
|
private $bodyLocalized; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var Localized |
43
|
|
|
*/ |
44
|
|
|
private $actionLocalized; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private $launchImage = ''; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Constructor. |
53
|
|
|
* |
54
|
|
|
* @param string $body |
55
|
|
|
* @param string $title |
56
|
|
|
*/ |
57
|
|
|
public function __construct(string $body = '', string $title = '') |
58
|
|
|
{ |
59
|
|
|
$this->body = $body; |
60
|
|
|
$this->title = $title; |
61
|
|
|
$this->titleLocalized = new Localized(''); |
62
|
|
|
$this->bodyLocalized = new Localized(''); |
63
|
|
|
$this->actionLocalized = new Localized(''); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Set title |
68
|
|
|
* |
69
|
|
|
* @param string $title |
70
|
|
|
* |
71
|
|
|
* @return Alert |
72
|
|
|
*/ |
73
|
|
|
public function withTitle(string $title): Alert |
74
|
|
|
{ |
75
|
|
|
$cloned = clone $this; |
76
|
|
|
|
77
|
|
|
$cloned->titleLocalized = new Localized(''); |
78
|
|
|
$cloned->title = $title; |
79
|
|
|
|
80
|
|
|
return $cloned; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* With localized title |
85
|
|
|
* |
86
|
|
|
* @param Localized $localized |
87
|
|
|
* |
88
|
|
|
* @return Alert |
89
|
|
|
*/ |
90
|
|
|
public function withLocalizedTitle(Localized $localized): Alert |
91
|
|
|
{ |
92
|
|
|
$cloned = clone $this; |
93
|
|
|
|
94
|
|
|
$cloned->title = ''; |
95
|
|
|
$cloned->titleLocalized = $localized; |
96
|
|
|
|
97
|
|
|
return $cloned; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Get title |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function getTitle(): string |
106
|
|
|
{ |
107
|
|
|
return $this->title; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get localized title |
112
|
|
|
* |
113
|
|
|
* @return Localized |
114
|
|
|
*/ |
115
|
|
|
public function getTitleLocalized(): Localized |
116
|
|
|
{ |
117
|
|
|
return $this->titleLocalized; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Set body |
122
|
|
|
* |
123
|
|
|
* @param string $body |
124
|
|
|
* |
125
|
|
|
* @return Alert |
126
|
|
|
*/ |
127
|
|
View Code Duplication |
public function withBody(string $body): Alert |
128
|
|
|
{ |
129
|
|
|
$cloned = clone $this; |
130
|
|
|
|
131
|
|
|
$cloned->bodyLocalized = new Localized(''); |
132
|
|
|
$cloned->body = $body; |
133
|
|
|
|
134
|
|
|
return $cloned; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Set localized body |
139
|
|
|
* |
140
|
|
|
* @param Localized $localized |
141
|
|
|
* |
142
|
|
|
* @return Alert |
143
|
|
|
*/ |
144
|
|
View Code Duplication |
public function withBodyLocalized(Localized $localized): Alert |
145
|
|
|
{ |
146
|
|
|
$cloned = clone $this; |
147
|
|
|
|
148
|
|
|
$cloned->body = ''; |
149
|
|
|
$cloned->bodyLocalized = $localized; |
150
|
|
|
|
151
|
|
|
return $cloned; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Get localized body |
156
|
|
|
* |
157
|
|
|
* @return Localized |
158
|
|
|
*/ |
159
|
|
|
public function getBodyLocalized(): Localized |
160
|
|
|
{ |
161
|
|
|
return $this->bodyLocalized; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Get body |
166
|
|
|
* |
167
|
|
|
* @return string |
168
|
|
|
*/ |
169
|
|
|
public function getBody(): string |
170
|
|
|
{ |
171
|
|
|
return $this->body; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* With localized action |
176
|
|
|
* |
177
|
|
|
* @param Localized $localized |
178
|
|
|
* |
179
|
|
|
* @return Alert |
180
|
|
|
*/ |
181
|
|
|
public function withActionLocalized(Localized $localized): Alert |
182
|
|
|
{ |
183
|
|
|
$cloned = clone $this; |
184
|
|
|
|
185
|
|
|
$cloned->actionLocalized = $localized; |
186
|
|
|
|
187
|
|
|
return $cloned; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Get localized action |
192
|
|
|
* |
193
|
|
|
* @return Localized |
194
|
|
|
*/ |
195
|
|
|
public function getActionLocalized(): Localized |
196
|
|
|
{ |
197
|
|
|
return $this->actionLocalized; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Add launch image |
202
|
|
|
* |
203
|
|
|
* @param string $launchImage |
204
|
|
|
* |
205
|
|
|
* @return Alert |
206
|
|
|
*/ |
207
|
|
|
public function withLaunchImage(string $launchImage): Alert |
208
|
|
|
{ |
209
|
|
|
$cloned = clone $this; |
210
|
|
|
|
211
|
|
|
$cloned->launchImage = $launchImage; |
212
|
|
|
|
213
|
|
|
return $cloned; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Get launch image |
218
|
|
|
* |
219
|
|
|
* @return string |
220
|
|
|
*/ |
221
|
|
|
public function getLaunchImage(): string |
222
|
|
|
{ |
223
|
|
|
return $this->launchImage; |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|