1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Nexylan packages. |
7
|
|
|
* |
8
|
|
|
* (c) Nexylan SAS <[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 Nexy\Slack; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Sullivan Senechal <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
final class AttachmentAction |
20
|
|
|
{ |
21
|
|
|
const TYPE_BUTTON = 'button'; |
22
|
|
|
|
23
|
|
|
const STYLE_DEFAULT = 'default'; |
24
|
|
|
const STYLE_PRIMARY = 'primary'; |
25
|
|
|
const STYLE_DANGER = 'danger'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The required name field of the action. The name will be returned to your Action URL. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $name; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The required label for the action. |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
private $text; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Button style. |
43
|
|
|
* |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
private $style = self::STYLE_DEFAULT; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* The required type of the action. |
50
|
|
|
* |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
private $type = self::TYPE_BUTTON; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Optional value. It will be sent to your Action URL. |
57
|
|
|
* |
58
|
|
|
* @var string|null |
59
|
|
|
*/ |
60
|
|
|
private $value; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Confirmation field. |
64
|
|
|
* |
65
|
|
|
* @var ActionConfirmation|null |
66
|
|
|
*/ |
67
|
|
|
private $confirm; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $name |
71
|
|
|
* @param string $text |
72
|
|
|
*/ |
73
|
|
|
public function __construct(string $name, string $text) |
74
|
|
|
{ |
75
|
|
|
$this->name = $name; |
76
|
|
|
$this->text = $text; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getName(): string |
83
|
|
|
{ |
84
|
|
|
return $this->name; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function getText(): string |
91
|
|
|
{ |
92
|
|
|
return $this->text; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function getStyle(): string |
99
|
|
|
{ |
100
|
|
|
return $this->style; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param string $style |
105
|
|
|
* |
106
|
|
|
* @return AttachmentAction |
107
|
|
|
*/ |
108
|
|
|
public function setStyle(string $style) |
109
|
|
|
{ |
110
|
|
|
$this->style = $style; |
111
|
|
|
|
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public function getType(): string |
119
|
|
|
{ |
120
|
|
|
return $this->type; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param string $type |
125
|
|
|
* |
126
|
|
|
* @return AttachmentAction |
127
|
|
|
*/ |
128
|
|
|
public function setType(string $type) |
129
|
|
|
{ |
130
|
|
|
$this->type = $type; |
131
|
|
|
|
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return string|null |
137
|
|
|
*/ |
138
|
|
|
public function getValue(): ?string |
139
|
|
|
{ |
140
|
|
|
return $this->value; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param string $value |
145
|
|
|
* |
146
|
|
|
* @return AttachmentAction |
147
|
|
|
*/ |
148
|
|
|
public function setValue(?string $value) |
149
|
|
|
{ |
150
|
|
|
$this->value = $value; |
151
|
|
|
|
152
|
|
|
return $this; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return ActionConfirmation|null |
157
|
|
|
*/ |
158
|
|
|
public function getConfirm(): ?ActionConfirmation |
159
|
|
|
{ |
160
|
|
|
return $this->confirm; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param ActionConfirmation $confirm |
165
|
|
|
* |
166
|
|
|
* @return AttachmentAction|null |
167
|
|
|
*/ |
168
|
|
|
public function setConfirm(?ActionConfirmation $confirm) |
169
|
|
|
{ |
170
|
|
|
$this->confirm = $confirm; |
171
|
|
|
|
172
|
|
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Get the array representation of this attachment action. |
177
|
|
|
* |
178
|
|
|
* @return array |
179
|
|
|
*/ |
180
|
|
|
public function toArray() |
181
|
|
|
{ |
182
|
|
|
return [ |
183
|
|
|
'name' => $this->name, |
184
|
|
|
'text' => $this->text, |
185
|
|
|
'style' => $this->style, |
186
|
|
|
'type' => $this->type, |
187
|
|
|
'value' => $this->value, |
188
|
|
|
'confirm' => $this->confirm ? $this->confirm->toArray() : null, |
189
|
|
|
]; |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|