1
|
|
|
<?php |
2
|
|
|
namespace Maknz\Slack\BlockElement; |
3
|
|
|
|
4
|
|
|
use Maknz\Slack\BlockElement; |
5
|
|
|
use Maknz\Slack\BlockElement\Text; |
6
|
|
|
|
7
|
|
|
class TextInput extends BlockElement |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Block type. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $type = 'plain_text_input'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Input action. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $action_id; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Placeholder shown on the input. |
25
|
|
|
* |
26
|
|
|
* @var \Maknz\Slack\BlockElement\Text |
27
|
|
|
*/ |
28
|
|
|
protected $placeholder; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Input initial value. |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $initial_value; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Whether the input spans multiple lines. |
39
|
|
|
* |
40
|
|
|
* @var bool |
41
|
|
|
*/ |
42
|
|
|
protected $multiline = false; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Minimum length of the input. |
46
|
|
|
* |
47
|
|
|
* @var int |
48
|
|
|
*/ |
49
|
|
|
protected $min_length; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Maximum length of the input. |
53
|
|
|
* |
54
|
|
|
* @var int |
55
|
|
|
*/ |
56
|
|
|
protected $max_length; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Internal attribute to property map. |
60
|
|
|
* |
61
|
|
|
* @var array |
62
|
|
|
*/ |
63
|
|
|
protected static $availableAttributes = [ |
64
|
|
|
'action_id' => 'action_id', |
65
|
|
|
'placeholder' => 'placeholder', |
66
|
|
|
'initial_value' => 'initial_value', |
67
|
|
|
'multiline' => 'multiline', |
68
|
|
|
'min_length' => 'min_length', |
69
|
|
|
'max_length' => 'max_length', |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Get the action. |
74
|
|
|
* |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
3 |
|
public function getActionId() |
78
|
|
|
{ |
79
|
3 |
|
return $this->action_id; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Set the action. |
84
|
|
|
* |
85
|
|
|
* @param string $actionId |
86
|
|
|
* |
87
|
|
|
* @return TextInput |
88
|
|
|
*/ |
89
|
4 |
|
public function setActionId($actionId) |
90
|
|
|
{ |
91
|
4 |
|
$this->action_id = $actionId; |
92
|
|
|
|
93
|
4 |
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get the placeholder. |
98
|
|
|
* |
99
|
|
|
* @return \Maknz\Slack\BlockElement\Text |
100
|
|
|
*/ |
101
|
3 |
|
public function getPlaceholder() |
102
|
|
|
{ |
103
|
3 |
|
return $this->placeholder; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Set the placeholder. |
108
|
|
|
* |
109
|
|
|
* @param mixed $placeholder |
110
|
|
|
* |
111
|
|
|
* @return TextInput |
112
|
|
|
* |
113
|
|
|
* @throws \InvalidArgumentException |
114
|
|
|
*/ |
115
|
2 |
|
public function setPlaceholder($placeholder) |
116
|
|
|
{ |
117
|
2 |
|
$this->placeholder = Text::create($placeholder, Text::TYPE_PLAIN); |
118
|
|
|
|
119
|
2 |
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Get the initial value. |
124
|
|
|
* |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
2 |
|
public function getInitialValue() |
128
|
|
|
{ |
129
|
2 |
|
return $this->initial_value; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Set the initial value |
134
|
|
|
* |
135
|
|
|
* @param string $initialValue |
136
|
|
|
* |
137
|
|
|
* @return TextInput |
138
|
|
|
*/ |
139
|
1 |
|
public function setInitialValue($initialValue) |
140
|
|
|
{ |
141
|
1 |
|
$this->initial_value = $initialValue; |
142
|
|
|
|
143
|
1 |
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Get whether the input spans multiple lines. |
148
|
|
|
* |
149
|
|
|
* @return bool |
150
|
|
|
*/ |
151
|
2 |
|
public function getMultiline() |
152
|
|
|
{ |
153
|
2 |
|
return $this->multiline; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Set whether the input spans multiple lines. |
158
|
|
|
* |
159
|
|
|
* @param bool $multiline |
160
|
|
|
* |
161
|
|
|
* @return TextInput |
162
|
|
|
*/ |
163
|
|
|
public function setMultiline($multiline) |
164
|
|
|
{ |
165
|
|
|
$this->multiline = (bool)$multiline; |
166
|
|
|
|
167
|
|
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Get the input minimum length. |
172
|
|
|
* |
173
|
|
|
* @return int |
174
|
|
|
*/ |
175
|
2 |
|
public function getMinLength() |
176
|
|
|
{ |
177
|
2 |
|
return $this->min_length; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Set the input minimum length. |
182
|
|
|
* |
183
|
|
|
* @param int $minLength |
184
|
|
|
* |
185
|
|
|
* @return TextInput |
186
|
|
|
*/ |
187
|
1 |
|
public function setMinLength($minLength) |
188
|
|
|
{ |
189
|
1 |
|
$this->min_length = $minLength; |
190
|
|
|
|
191
|
1 |
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Get the input maximum length. |
196
|
|
|
* |
197
|
|
|
* @return int |
198
|
|
|
*/ |
199
|
2 |
|
public function getMaxLength() |
200
|
|
|
{ |
201
|
2 |
|
return $this->max_length; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Set the input maximum length. |
206
|
|
|
* |
207
|
|
|
* @param int $maxLength |
208
|
|
|
* |
209
|
|
|
* @return TextInput |
210
|
|
|
*/ |
211
|
1 |
|
public function setMaxLength($maxLength) |
212
|
|
|
{ |
213
|
1 |
|
$this->max_length = $maxLength; |
214
|
|
|
|
215
|
1 |
|
return $this; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Convert the block to its array representation. |
220
|
|
|
* |
221
|
|
|
* @return array |
222
|
|
|
*/ |
223
|
2 |
|
public function toArray() |
224
|
|
|
{ |
225
|
|
|
$data = [ |
226
|
2 |
|
'type' => $this->getType(), |
227
|
2 |
|
'action_id' => $this->getActionId(), |
228
|
|
|
]; |
229
|
|
|
|
230
|
2 |
|
if ($this->getPlaceholder()) { |
231
|
1 |
|
$data['placeholder'] = $this->getPlaceholder()->toArray(); |
232
|
|
|
} |
233
|
|
|
|
234
|
2 |
|
if ($this->getInitialValue()) { |
235
|
1 |
|
$data['initial_value'] = $this->getInitialValue(); |
236
|
|
|
} |
237
|
|
|
|
238
|
2 |
|
if ($this->getMultiline() != null) { |
239
|
|
|
$data['multiline'] = $this->getMultiline(); |
240
|
|
|
} |
241
|
|
|
|
242
|
2 |
|
if ($this->getMinLength()) { |
243
|
1 |
|
$data['min_length'] = $this->getMinLength(); |
244
|
|
|
} |
245
|
|
|
|
246
|
2 |
|
if ($this->getMaxLength()) { |
247
|
1 |
|
$data['max_length'] = $this->getMaxLength(); |
248
|
|
|
} |
249
|
|
|
|
250
|
2 |
|
return $data; |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|