Completed
Pull Request — master (#26)
by
unknown
01:14
created

Alert::getBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Pushok package.
5
 *
6
 * (c) Arthur Edamov <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Pushok\Payload;
13
14
/**
15
 * Class Alert
16
 *
17
 * @package Pushok\Payload
18
 *
19
 * @see http://bit.ly/payload-key-reference
20
 */
21
class Alert implements \JsonSerializable
22
{
23
    const ALERT_TITLE_KEY = 'title';
24
    const ALERT_BODY_KEY = 'body';
25
    const ALERT_TITLE_LOC_KEY = 'loc-key';
26
    const ALERT_TITLE_LOC_ARGS_KEY = 'loc-args';
27
    const ALERT_ACTION_LOC_KEY = 'action-loc-key';
28
    const ALERT_LOC_KEY = 'loc-key';
29
    const ALERT_LOC_ARGS_KEY = 'loc-args';
30
    const ALERT_LAUNCH_IMAGE_KEY = 'launch-image';
31
32
    /**
33
     * A short string describing the purpose of the notification.
34
     *
35
     * @var string
36
     */
37
    private $title;
38
39
    /**
40
     * A subtitle.
41
     *
42
     * @var string
43
     */
44
    private $subtitle;
45
46
    /**
47
     * The text of the alert message.
48
     *
49
     * @var string
50
     */
51
    private $body;
52
53
    /**
54
     * The key to a title string in the Localizable.strings file for the current localization.
55
     *
56
     * @var string|null
57
     */
58
    private $titleLocKey;
59
60
    /**
61
     * Variable string values to appear in place of the format specifiers in title-loc-key.
62
     *
63
     * @var string[]|null
64
     */
65
    private $titleLocArgs;
66
67
    /**
68
     * If a string is specified, the iOS system displays an alert that includes the Close and View buttons.
69
     *
70
     * @var string|null
71
     */
72
    private $actionLocKey;
73
74
    /**
75
     * A key to an alert-message string in a Localizable.strings file for the current localization.
76
     *
77
     * @var string
78
     */
79
    private $locKey;
80
81
    /**
82
     * Variable string values to appear in place of the format specifiers in loc-key.
83
     *
84
     * @var string[]
85
     */
86
    private $locArgs;
87
88
    /**
89
     * The filename of an image file in the app bundle, with or without the filename extension.
90
     *
91
     * @var string
92
     */
93
    private $launchImage;
94
95
    protected function __construct()
96
    {
97
    }
98
99
    public static function create()
100
    {
101
        return new self();
102
    }
103
104
    /**
105
     * Set Alert title.
106
     *
107
     * @param string $value
108
     * @return Alert
109
     */
110
    public function setTitle(string $value): Alert
111
    {
112
        $this->title = $value;
113
114
        return $this;
115
    }
116
117
    /**
118
     * Get Alert title.
119
     *
120
     * @return string
121
     */
122
    public function getTitle()
123
    {
124
        return $this->title;
125
    }
126
127
    /**
128
     * Set Alert title.
129
     *
130
     * @param string $value
131
     * @return Alert
132
     */
133
    public function setSubtitle(string $value): Alert
134
    {
135
        $this->subtitle = $value;
136
137
        return $this;
138
    }
139
140
    /**
141
     * Get Alert subtitle.
142
     *
143
     * @return string
144
     */
145
    public function getSubtitle()
146
    {
147
        return $this->subtitle;
148
    }
149
150
    /**
151
     * Set Alert body.
152
     *
153
     * @param string $value
154
     * @return Alert
155
     */
156
    public function setBody(string $value): Alert
157
    {
158
        $this->body = $value;
159
160
        return $this;
161
    }
162
163
    /**
164
     * Get Alert body.
165
     *
166
     * @return string
167
     */
168
    public function getBody()
169
    {
170
        return $this->body;
171
    }
172
173
    /**
174
     * Set title-loc-key.
175
     *
176
     * @param string|null $value
177
     * @return Alert
178
     */
179
    public function setTitleLocKey(string $value = null): Alert
180
    {
181
        $this->titleLocKey = $value;
182
183
        return $this;
184
    }
185
186
    /**
187
     * Get title-loc-key.
188
     *
189
     * @return string
190
     */
191
    public function getTitleLocKey()
192
    {
193
        return $this->titleLocKey;
194
    }
195
196
    /**
197
     * Set title-loc-args.
198
     *
199
     * @param array|null $value
200
     * @return Alert
201
     */
202
    public function setTitleLocArgs(array $value = null): Alert
203
    {
204
        $this->titleLocArgs = $value;
205
206
        return $this;
207
    }
208
209
    /**
210
     * Get title-loc-args.
211
     *
212
     * @return string[]|null
213
     */
214
    public function getTitleLocArgs()
215
    {
216
        return $this->titleLocArgs;
217
    }
218
219
    /**
220
     * Set action-loc-key.
221
     *
222
     * @param string|null $value
223
     * @return Alert
224
     */
225
    public function setActionLocKey(string $value = null): Alert
226
    {
227
        $this->actionLocKey = $value;
228
229
        return $this;
230
    }
231
232
    /**
233
     * Get action-loc-key.
234
     *
235
     * @return string|null
236
     */
237
    public function getActionLocKey()
238
    {
239
        return $this->actionLocKey;
240
    }
241
242
    /**
243
     * Set loc-key.
244
     *
245
     * @param string $value
246
     * @return Alert
247
     */
248
    public function setLocKey(string $value): Alert
249
    {
250
        $this->locKey = $value;
251
252
        return $this;
253
    }
254
255
    /**
256
     * Get loc-key.
257
     *
258
     * @return string
259
     */
260
    public function getLocKey()
261
    {
262
        return $this->locKey;
263
    }
264
265
    /**
266
     * Set loc-args.
267
     *
268
     * @param array $value
269
     * @return Alert
270
     */
271
    public function setLocArgs(array $value): Alert
272
    {
273
        $this->locArgs = $value;
274
275
        return $this;
276
    }
277
278
    /**
279
     * Get loc-args.
280
     *
281
     * @return string[]
282
     */
283
    public function getLocArgs()
284
    {
285
        return $this->locArgs;
286
    }
287
288
    /**
289
     * Set launch-image.
290
     *
291
     * @param string $value
292
     * @return $this
293
     */
294
    public function setLaunchImage(string $value)
295
    {
296
        $this->launchImage = $value;
297
298
        return $this;
299
    }
300
301
    /**
302
     * Get launch-image.
303
     *
304
     * @return string
305
     */
306
    public function getLaunchImage()
307
    {
308
        return $this->launchImage;
309
    }
310
311
    /**
312
     * Convert Alert to JSON.
313
     *
314
     * @return string
315
     */
316
    public function toJson(): string
317
    {
318
        return json_encode($this, JSON_UNESCAPED_UNICODE);
319
    }
320
321
    /**
322
     * Specify data which should be serialized to JSON.
323
     *
324
     * @return array
325
     * @link   http://php.net/manual/en/jsonserializable.jsonserialize.php
326
     */
327
    public function jsonSerialize()
328
    {
329
        $alert = [];
330
331
        if (is_string($this->title)) {
332
            $alert[self::ALERT_TITLE_KEY] = $this->title;
333
        }
334
335
        if (is_string($this->body)) {
336
            $alert[self::ALERT_BODY_KEY] = $this->body;
337
        }
338
339
        if (is_string($this->titleLocKey)) {
340
            $alert[self::ALERT_TITLE_LOC_KEY] = $this->titleLocKey;
341
        }
342
343
        if (is_array($this->titleLocArgs)) {
344
            $alert[self::ALERT_TITLE_LOC_ARGS_KEY] = $this->titleLocArgs;
345
        }
346
347
        if (is_string($this->actionLocKey)) {
348
            $alert[self::ALERT_ACTION_LOC_KEY] = $this->actionLocKey;
349
        }
350
351
        if (is_string($this->locKey)) {
352
            $alert[self::ALERT_LOC_KEY] = $this->locKey;
353
        }
354
355
        if (is_array($this->locArgs)) {
356
            $alert[self::ALERT_LOC_ARGS_KEY] = $this->locArgs;
357
        }
358
359
        if (is_string($this->launchImage)) {
360
            $alert[self::ALERT_LAUNCH_IMAGE_KEY] = $this->launchImage;
361
        }
362
363
        return $alert;
364
    }
365
}
366