1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlexLisenkov\LaravelWebPush; |
4
|
|
|
|
5
|
|
|
use AlexLisenkov\LaravelWebPush\Contracts\MessageActionContract; |
6
|
|
|
|
7
|
|
|
class MessageAction implements MessageActionContract |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* A DOMString identifying a user action to be displayed on the notification. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $action; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* A DOMString containing action text to be shown to the user. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $title; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* A USVString containing the URL of an icon to display with the action. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $icon; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
1 |
|
public function __toString(): string |
34
|
|
|
{ |
35
|
1 |
|
return (string)$this->toJson(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Convert the object to its JSON representation. |
40
|
|
|
* |
41
|
|
|
* @param int $options |
42
|
|
|
* |
43
|
|
|
* @return false|string |
44
|
|
|
*/ |
45
|
3 |
|
public function toJson($options = PushMessage::DEFAULT_ENCODING_OPTIONS) |
46
|
|
|
{ |
47
|
3 |
|
return json_encode($this->toArray(), $options); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get the instance as an array. |
52
|
|
|
* |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
5 |
|
public function toArray(): array |
56
|
|
|
{ |
57
|
|
|
return [ |
58
|
5 |
|
'action' => $this->getAction(), |
59
|
5 |
|
'title' => $this->getTitle(), |
60
|
5 |
|
'icon' => $this->getIcon(), |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get Action |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
6 |
|
public function getAction(): string |
70
|
|
|
{ |
71
|
6 |
|
return $this->action; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Set Action |
76
|
|
|
* |
77
|
|
|
* @param string $action |
78
|
|
|
* |
79
|
|
|
* @return MessageAction |
80
|
|
|
*/ |
81
|
5 |
|
public function setAction(string $action): MessageAction |
82
|
|
|
{ |
83
|
5 |
|
$this->action = $action; |
84
|
|
|
|
85
|
5 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get Title |
90
|
|
|
* |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
6 |
|
public function getTitle(): string |
94
|
|
|
{ |
95
|
6 |
|
return $this->title; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Set Title |
100
|
|
|
* |
101
|
|
|
* @param string $title |
102
|
|
|
* |
103
|
|
|
* @return MessageAction |
104
|
|
|
*/ |
105
|
5 |
|
public function setTitle(string $title): MessageAction |
106
|
|
|
{ |
107
|
5 |
|
$this->title = $title; |
108
|
|
|
|
109
|
5 |
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Get Icon |
114
|
|
|
* |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
6 |
|
public function getIcon(): ?string |
118
|
|
|
{ |
119
|
6 |
|
return $this->icon; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Set Icon |
124
|
|
|
* |
125
|
|
|
* @param string $icon |
126
|
|
|
* |
127
|
|
|
* @return MessageAction |
128
|
|
|
*/ |
129
|
5 |
|
public function setIcon(string $icon): MessageAction |
130
|
|
|
{ |
131
|
5 |
|
$this->icon = $icon; |
132
|
|
|
|
133
|
5 |
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Specify data which should be serialized to JSON |
138
|
|
|
* |
139
|
|
|
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php |
140
|
|
|
* @return mixed data which can be serialized by <b>json_encode</b>, |
141
|
|
|
* which is a value of any type other than a resource. |
142
|
|
|
* @since 5.4.0 |
143
|
|
|
*/ |
144
|
1 |
|
public function jsonSerialize(): string |
145
|
|
|
{ |
146
|
1 |
|
return $this->toJson(); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|