Completed
Push — master ( 9b760e...8a0b19 )
by Arthur
01:59
created

Alert::getTitleLocKey()   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 = 'title-loc-key';
26
    const ALERT_TITLE_LOC_ARGS_KEY = 'title-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
    const ALERT_MUTABLE_CONTENT_KEY = 'mutable-content';
32
33
    /**
34
     * A short string describing the purpose of the notification.
35
     *
36
     * @var string
37
     */
38
    private $title;
39
40
    /**
41
     * A subtitle.
42
     *
43
     * @var string
44
     */
45
    private $subtitle;
46
47
    /**
48
     * The text of the alert message.
49
     *
50
     * @var string
51
     */
52
    private $body;
53
54
    /**
55
     * The key to a title string in the Localizable.strings file for the current localization.
56
     *
57
     * @var string|null
58
     */
59
    private $titleLocKey;
60
61
    /**
62
     * Variable string values to appear in place of the format specifiers in title-loc-key.
63
     *
64
     * @var string[]|null
65
     */
66
    private $titleLocArgs;
67
68
    /**
69
     * If a string is specified, the iOS system displays an alert that includes the Close and View buttons.
70
     *
71
     * @var string|null
72
     */
73
    private $actionLocKey;
74
75
    /**
76
     * A key to an alert-message string in a Localizable.strings file for the current localization.
77
     *
78
     * @var string
79
     */
80
    private $locKey;
81
82
    /**
83
     * Variable string values to appear in place of the format specifiers in loc-key.
84
     *
85
     * @var string[]
86
     */
87
    private $locArgs;
88
89
    /**
90
     * The filename of an image file in the app bundle, with or without the filename extension.
91
     *
92
     * @var string
93
     */
94
    private $launchImage;
95
96
    /**
97
     * Access to modify the content of remote notifications before they are delivered to the user.
98
     *
99
     * @var bool
100
     */
101
    private $mutableContent;
102
103
    protected function __construct()
104
    {
105
    }
106
107
    public static function create()
108
    {
109
        return new self();
110
    }
111
112
    /**
113
     * Set Alert title.
114
     *
115
     * @param string $value
116
     * @return Alert
117
     */
118
    public function setTitle(string $value): Alert
119
    {
120
        $this->title = $value;
121
122
        return $this;
123
    }
124
125
    /**
126
     * Get Alert title.
127
     *
128
     * @return string
129
     */
130
    public function getTitle()
131
    {
132
        return $this->title;
133
    }
134
135
    /**
136
     * Set Alert title.
137
     *
138
     * @param string $value
139
     * @return Alert
140
     */
141
    public function setSubtitle(string $value): Alert
142
    {
143
        $this->subtitle = $value;
144
145
        return $this;
146
    }
147
148
    /**
149
     * Get Alert subtitle.
150
     *
151
     * @return string
152
     */
153
    public function getSubtitle()
154
    {
155
        return $this->subtitle;
156
    }
157
158
    /**
159
     * Set Alert body.
160
     *
161
     * @param string $value
162
     * @return Alert
163
     */
164
    public function setBody(string $value): Alert
165
    {
166
        $this->body = $value;
167
168
        return $this;
169
    }
170
171
    /**
172
     * Get Alert body.
173
     *
174
     * @return string
175
     */
176
    public function getBody()
177
    {
178
        return $this->body;
179
    }
180
181
    /**
182
     * Set title-loc-key.
183
     *
184
     * @param string|null $value
185
     * @return Alert
186
     */
187
    public function setTitleLocKey(string $value = null): Alert
188
    {
189
        $this->titleLocKey = $value;
190
191
        return $this;
192
    }
193
194
    /**
195
     * Get title-loc-key.
196
     *
197
     * @return string
198
     */
199
    public function getTitleLocKey()
200
    {
201
        return $this->titleLocKey;
202
    }
203
204
    /**
205
     * Set title-loc-args.
206
     *
207
     * @param array|null $value
208
     * @return Alert
209
     */
210
    public function setTitleLocArgs(array $value = null): Alert
211
    {
212
        $this->titleLocArgs = $value;
213
214
        return $this;
215
    }
216
217
    /**
218
     * Get title-loc-args.
219
     *
220
     * @return string[]|null
221
     */
222
    public function getTitleLocArgs()
223
    {
224
        return $this->titleLocArgs;
225
    }
226
227
    /**
228
     * Set action-loc-key.
229
     *
230
     * @param string|null $value
231
     * @return Alert
232
     */
233
    public function setActionLocKey(string $value = null): Alert
234
    {
235
        $this->actionLocKey = $value;
236
237
        return $this;
238
    }
239
240
    /**
241
     * Get action-loc-key.
242
     *
243
     * @return string|null
244
     */
245
    public function getActionLocKey()
246
    {
247
        return $this->actionLocKey;
248
    }
249
250
    /**
251
     * Set loc-key.
252
     *
253
     * @param string $value
254
     * @return Alert
255
     */
256
    public function setLocKey(string $value): Alert
257
    {
258
        $this->locKey = $value;
259
260
        return $this;
261
    }
262
263
    /**
264
     * Get loc-key.
265
     *
266
     * @return string
267
     */
268
    public function getLocKey()
269
    {
270
        return $this->locKey;
271
    }
272
273
    /**
274
     * Set loc-args.
275
     *
276
     * @param array $value
277
     * @return Alert
278
     */
279
    public function setLocArgs(array $value): Alert
280
    {
281
        $this->locArgs = $value;
282
283
        return $this;
284
    }
285
286
    /**
287
     * Get loc-args.
288
     *
289
     * @return string[]
290
     */
291
    public function getLocArgs()
292
    {
293
        return $this->locArgs;
294
    }
295
296
    /**
297
     * Set launch-image.
298
     *
299
     * @param string $value
300
     * @return $this
301
     */
302
    public function setLaunchImage(string $value)
303
    {
304
        $this->launchImage = $value;
305
306
        return $this;
307
    }
308
309
    /**
310
     * Get launch-image.
311
     *
312
     * @return string
313
     */
314
    public function getLaunchImage()
315
    {
316
        return $this->launchImage;
317
    }
318
319
    /**
320
     * Set the mutable-content key for Notification Service Extensions on iOS10.
321
     * @see http://bit.ly/mutable-content
322
     *
323
     * @param bool $value
324
     * @return Alert
325
     */
326
    public function setMutableContent(bool $value): Alert
327
    {
328
        $this->mutableContent = $value;
329
330
        return $this;
331
    }
332
333
    /**
334
     * Is content mutable.
335
     *
336
     * @return bool|null
337
     */
338
    public function hasMutableContent()
339
    {
340
        return $this->mutableContent;
341
    }
342
343
    /**
344
     * Convert Alert to JSON.
345
     *
346
     * @return string
347
     */
348
    public function toJson(): string
349
    {
350
        return json_encode($this, JSON_UNESCAPED_UNICODE);
351
    }
352
353
    /**
354
     * Specify data which should be serialized to JSON.
355
     *
356
     * @return array
357
     * @link   http://php.net/manual/en/jsonserializable.jsonserialize.php
358
     */
359
    public function jsonSerialize()
360
    {
361
        $alert = [];
362
363
        if (is_string($this->title)) {
364
            $alert[self::ALERT_TITLE_KEY] = $this->title;
365
        }
366
367
        if (is_string($this->body)) {
368
            $alert[self::ALERT_BODY_KEY] = $this->body;
369
        }
370
371
        if (is_string($this->titleLocKey)) {
372
            $alert[self::ALERT_TITLE_LOC_KEY] = $this->titleLocKey;
373
        }
374
375
        if (is_array($this->titleLocArgs)) {
376
            $alert[self::ALERT_TITLE_LOC_ARGS_KEY] = $this->titleLocArgs;
377
        }
378
379
        if (is_string($this->actionLocKey)) {
380
            $alert[self::ALERT_ACTION_LOC_KEY] = $this->actionLocKey;
381
        }
382
383
        if (is_string($this->locKey)) {
384
            $alert[self::ALERT_LOC_KEY] = $this->locKey;
385
        }
386
387
        if (is_array($this->locArgs)) {
388
            $alert[self::ALERT_LOC_ARGS_KEY] = $this->locArgs;
389
        }
390
391
        if (is_string($this->launchImage)) {
392
            $alert[self::ALERT_LAUNCH_IMAGE_KEY] = $this->launchImage;
393
        }
394
395
        if (is_bool($this->mutableContent)) {
396
            $alert[self::ALERT_MUTABLE_CONTENT_KEY] = (int)$this->mutableContent;
397
        }
398
399
        return $alert;
400
    }
401
}
402