|
1
|
|
|
<?php namespace nyx\notify\transports\slack\message\attachment\actions; |
|
2
|
|
|
|
|
3
|
|
|
// External dependencies |
|
4
|
|
|
use nyx\core; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Slack Message Confirmation Action |
|
8
|
|
|
* |
|
9
|
|
|
* See {@see https://api.slack.com/docs/message-buttons#confirmation_fields} for Slack's documentation on |
|
10
|
|
|
* using Messages with Confirmation Actions. |
|
11
|
|
|
* |
|
12
|
|
|
* @package Nyx\Notify |
|
13
|
|
|
* @version 0.1.0 |
|
14
|
|
|
* @author Michal Chojnacki <[email protected]> |
|
15
|
|
|
* @copyright 2012-2017 Nyx Dev Team |
|
16
|
|
|
* @link https://github.com/unyx/nyx |
|
17
|
|
|
* @todo PHP7.1 pass for nullable return types (missing ?string on most methods). |
|
18
|
|
|
*/ |
|
19
|
|
|
class Confirmation implements core\interfaces\Serializable |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* The traits of a Confirmation Action. |
|
23
|
|
|
*/ |
|
24
|
|
|
use core\traits\Serializable; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string The title of the pop up window. Optional. |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $title; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string The description and context of the action about to be performed or cancelled. Required. |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $text; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string The text label for the button to continue with an action. Optional, defaults to "Okay". |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $okText; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var string The text label for the button to cancel the action. Optional, defaults to "Cancel". |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $dismissText; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Creates a new Confirmation instance. |
|
48
|
|
|
* |
|
49
|
|
|
* @param array $attributes |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct(array $attributes) |
|
52
|
|
|
{ |
|
53
|
|
|
if (!empty($attributes)) { |
|
54
|
|
|
$this->setAttributes($attributes); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Sets the attributes of this Confirmation. |
|
60
|
|
|
* |
|
61
|
|
|
* @param array $attributes |
|
62
|
|
|
* @return $this |
|
63
|
|
|
*/ |
|
64
|
|
|
public function setAttributes(array $attributes) : Confirmation |
|
65
|
|
|
{ |
|
66
|
|
|
if (isset($attributes['title'])) { |
|
67
|
|
|
$this->setTitle($attributes['title']); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if (isset($attributes['text'])) { |
|
71
|
|
|
$this->setText($attributes['text']); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if (isset($attributes['ok_text'])) { |
|
75
|
|
|
$this->setOkText($attributes['ok_text']); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (isset($attributes['dismiss_text'])) { |
|
79
|
|
|
$this->setDismissText($attributes['dismiss_text']); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Returns the title of the pop up window. |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getTitle() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->title; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Sets the title of the pop up window. |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $title |
|
99
|
|
|
* @return $this |
|
100
|
|
|
*/ |
|
101
|
|
|
public function setTitle(string $title) : Confirmation |
|
102
|
|
|
{ |
|
103
|
|
|
$this->title = $title; |
|
104
|
|
|
|
|
105
|
|
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Returns the description and context of the action about to be performed or cancelled. |
|
110
|
|
|
* |
|
111
|
|
|
* @return string |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getText() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->text; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Sets the description and context of the action about to be performed or cancelled. |
|
120
|
|
|
* |
|
121
|
|
|
* @param string $text |
|
122
|
|
|
* @return $this |
|
123
|
|
|
*/ |
|
124
|
|
|
public function setText(string $text) : Confirmation |
|
125
|
|
|
{ |
|
126
|
|
|
$this->text = $text; |
|
127
|
|
|
|
|
128
|
|
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Returns the text label for the button to continue with an action. |
|
133
|
|
|
* |
|
134
|
|
|
* @return string |
|
135
|
|
|
*/ |
|
136
|
|
|
public function getOkText() |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->okText; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Sets the text label for the button to continue with an action. |
|
143
|
|
|
* |
|
144
|
|
|
* @param string $okText |
|
145
|
|
|
* @return $this |
|
146
|
|
|
*/ |
|
147
|
|
|
public function setOkText(string $okText) |
|
148
|
|
|
{ |
|
149
|
|
|
$this->okText = $okText; |
|
150
|
|
|
|
|
151
|
|
|
return $this; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Returns the text label for the button to cancel the action. |
|
156
|
|
|
* |
|
157
|
|
|
* @return string |
|
158
|
|
|
*/ |
|
159
|
|
|
public function getDismissText() |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->dismissText; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Sets the text label for the button to cancel the action. |
|
166
|
|
|
* |
|
167
|
|
|
* @param string $dismissText |
|
168
|
|
|
* @return $this |
|
169
|
|
|
*/ |
|
170
|
|
|
public function setDismissText(string $dismissText) |
|
171
|
|
|
{ |
|
172
|
|
|
$this->dismissText = $dismissText; |
|
173
|
|
|
|
|
174
|
|
|
return $this; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* {@inheritDoc} |
|
179
|
|
|
*/ |
|
180
|
|
|
public function unserialize($data) |
|
181
|
|
|
{ |
|
182
|
|
|
$this->setAttributes(unserialize($data)); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* {@inheritDoc} |
|
187
|
|
|
*/ |
|
188
|
|
|
public function toArray() : array |
|
189
|
|
|
{ |
|
190
|
|
|
return [ |
|
191
|
|
|
'title' => $this->getTitle(), |
|
192
|
|
|
'text' => $this->getText(), |
|
193
|
|
|
'ok_text' => $this->getOkText(), |
|
194
|
|
|
'dismiss_text' => $this->getDismissText(), |
|
195
|
|
|
]; |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
|