|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the zibios/sharep. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Zbigniew Ślązak |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace App\Slack\MessageBuilder; |
|
12
|
|
|
|
|
13
|
|
|
use App\Slack\MessageBuilder\Block\ActionsBlock; |
|
14
|
|
|
use App\Slack\MessageBuilder\Block\BlockInterface; |
|
15
|
|
|
use App\Slack\MessageBuilder\Block\ContextBlock; |
|
16
|
|
|
use App\Slack\MessageBuilder\Block\DividerBlock; |
|
17
|
|
|
use App\Slack\MessageBuilder\Block\ImageBlock; |
|
18
|
|
|
use App\Slack\MessageBuilder\Block\InputBlock; |
|
19
|
|
|
use App\Slack\MessageBuilder\Block\SectionBlock; |
|
20
|
|
|
use App\Slack\MessageBuilder\Element\ActionsBlockElementInterface; |
|
21
|
|
|
use App\Slack\MessageBuilder\Element\ButtonElement; |
|
22
|
|
|
use App\Slack\MessageBuilder\Element\ContextBlockElementInterface; |
|
23
|
|
|
use App\Slack\MessageBuilder\Element\DatePickerElement; |
|
24
|
|
|
use App\Slack\MessageBuilder\Element\ImageElement; |
|
25
|
|
|
use App\Slack\MessageBuilder\Element\InputBlockElementInterface; |
|
26
|
|
|
use App\Slack\MessageBuilder\Element\MarkdownTextElement; |
|
27
|
|
|
use App\Slack\MessageBuilder\Element\MultiSelectExternalElement; |
|
28
|
|
|
use App\Slack\MessageBuilder\Element\MultiSelectStaticElement; |
|
29
|
|
|
use App\Slack\MessageBuilder\Element\MultiSelectStaticGroupElement; |
|
30
|
|
|
use App\Slack\MessageBuilder\Element\MultiSelectUserElement; |
|
31
|
|
|
use App\Slack\MessageBuilder\Element\OverflowMenuElement; |
|
32
|
|
|
use App\Slack\MessageBuilder\Element\PlainTextElement; |
|
33
|
|
|
use App\Slack\MessageBuilder\Element\PlainTextInputElement; |
|
34
|
|
|
use App\Slack\MessageBuilder\Element\RadioButtonGroupElement; |
|
35
|
|
|
use App\Slack\MessageBuilder\Element\SectionBlockElementInterface; |
|
36
|
|
|
use App\Slack\MessageBuilder\Element\SelectExternalElement; |
|
37
|
|
|
use App\Slack\MessageBuilder\Element\SelectStaticElement; |
|
38
|
|
|
use App\Slack\MessageBuilder\Element\SelectStaticGroupElement; |
|
39
|
|
|
use App\Slack\MessageBuilder\Element\SelectUserElement; |
|
40
|
|
|
use App\Slack\MessageBuilder\Element\TextElementInterface; |
|
41
|
|
|
use App\Slack\MessageBuilder\Enum\ButtonStyleEnum; |
|
42
|
|
|
use App\Slack\MessageBuilder\Object\ConfirmationDialogObject; |
|
43
|
|
|
use App\Slack\MessageBuilder\Object\OptionGroupObject; |
|
44
|
|
|
use App\Slack\MessageBuilder\Object\OptionObject; |
|
45
|
|
|
|
|
46
|
|
|
class MessageFactory |
|
47
|
|
|
{ |
|
48
|
3 |
|
public function layout(BlockInterface ...$blocks): Layout |
|
49
|
|
|
{ |
|
50
|
3 |
|
return new Layout(...$blocks); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
//------------------------------------------------------------------------------------------------------------------ |
|
54
|
|
|
|
|
55
|
1 |
|
public function blockActions(ActionsBlockElementInterface ...$elements): ActionsBlock |
|
56
|
|
|
{ |
|
57
|
1 |
|
return new ActionsBlock(...$elements); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function blockContext(ContextBlockElementInterface ...$elements): ContextBlock |
|
61
|
|
|
{ |
|
62
|
|
|
return new ContextBlock(...$elements); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function blockDivider(): DividerBlock |
|
66
|
|
|
{ |
|
67
|
|
|
return new DividerBlock(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function blockImage( |
|
71
|
|
|
string $imageUrl, |
|
72
|
|
|
string $altText, |
|
73
|
|
|
string $title = '' |
|
74
|
|
|
): ImageBlock { |
|
75
|
|
|
return new ImageBlock($imageUrl, $altText, $title); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function blockInput( |
|
79
|
|
|
string $label, |
|
80
|
|
|
InputBlockElementInterface $element, |
|
81
|
|
|
bool $optional = false, |
|
82
|
|
|
string $hint = '' |
|
83
|
|
|
): InputBlock { |
|
84
|
|
|
return new InputBlock($label, $element, $optional, $hint); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
3 |
|
public function blockSection( |
|
88
|
|
|
TextElementInterface $text, |
|
89
|
|
|
SectionBlockElementInterface $accessory = null, |
|
90
|
|
|
TextElementInterface ...$fields |
|
91
|
|
|
): SectionBlock { |
|
92
|
3 |
|
return new SectionBlock($text, $accessory, ...$fields); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
//------------------------------------------------------------------------------------------------------------------ |
|
96
|
|
|
|
|
97
|
1 |
|
public function elementButton( |
|
98
|
|
|
string $text, |
|
99
|
|
|
string $actionId, |
|
100
|
|
|
ButtonStyleEnum $style = null, |
|
101
|
|
|
ConfirmationDialogObject $confirm = null, |
|
102
|
|
|
string $value = '', |
|
103
|
|
|
string $url = '' |
|
104
|
|
|
): ButtonElement { |
|
105
|
1 |
|
return new ButtonElement($text, $actionId, $style, $confirm, $value, $url); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function elementDatePicker( |
|
109
|
|
|
string $actionId, |
|
110
|
|
|
string $placeholder = '', |
|
111
|
|
|
string $initialDate = '', |
|
112
|
|
|
ConfirmationDialogObject $confirmDialog = null |
|
113
|
|
|
): DatePickerElement { |
|
114
|
|
|
return new DatePickerElement($actionId, $placeholder, $initialDate, $confirmDialog); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function elementImage( |
|
118
|
|
|
string $imageUrl, |
|
119
|
|
|
string $altText |
|
120
|
|
|
): ImageElement { |
|
121
|
|
|
return new ImageElement($imageUrl, $altText); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function elementMarkdownText( |
|
125
|
|
|
string $text |
|
126
|
|
|
): MarkdownTextElement { |
|
127
|
|
|
return new MarkdownTextElement($text); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function elementMultiSelectExternal( |
|
131
|
|
|
string $placeholder, |
|
132
|
|
|
string $actionId, |
|
133
|
|
|
int $minQueryLength, |
|
134
|
|
|
array $initialOptions = [], |
|
135
|
|
|
ConfirmationDialogObject $confirmDialog = null |
|
136
|
|
|
): MultiSelectExternalElement { |
|
137
|
|
|
return new MultiSelectExternalElement($placeholder, $actionId, $minQueryLength, $initialOptions, $confirmDialog); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function elementMultiSelectStatic( |
|
141
|
|
|
string $placeholder, |
|
142
|
|
|
string $actionId, |
|
143
|
|
|
array $initialOptions = [], |
|
144
|
|
|
ConfirmationDialogObject $confirmDialog = null, |
|
145
|
|
|
OptionObject ...$options |
|
146
|
|
|
): MultiSelectStaticElement { |
|
147
|
|
|
return new MultiSelectStaticElement($placeholder, $actionId, $initialOptions, $confirmDialog, ...$options); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
1 |
|
public function elementMultiSelectStaticGroup( |
|
151
|
|
|
string $placeholder, |
|
152
|
|
|
string $actionId, |
|
153
|
|
|
array $initialOptions = [], |
|
154
|
|
|
ConfirmationDialogObject $confirmDialog = null, |
|
155
|
|
|
OptionGroupObject ...$optionGroups |
|
156
|
|
|
): MultiSelectStaticGroupElement { |
|
157
|
1 |
|
return new MultiSelectStaticGroupElement($placeholder, $actionId, $initialOptions, $confirmDialog, ...$optionGroups); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
public function elementMultiSelectUser( |
|
161
|
|
|
string $placeholder, |
|
162
|
|
|
string $actionId, |
|
163
|
|
|
array $initialUsers = [], |
|
164
|
|
|
ConfirmationDialogObject $confirmDialog = null |
|
165
|
|
|
): MultiSelectUserElement { |
|
166
|
|
|
return new MultiSelectUserElement($placeholder, $actionId, $initialUsers, $confirmDialog); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
public function elementOverflowMenu( |
|
170
|
|
|
string $placeholder, |
|
171
|
|
|
string $actionId, |
|
172
|
|
|
ConfirmationDialogObject $confirmDialog = null, |
|
173
|
|
|
OptionObject ...$options |
|
174
|
|
|
): OverflowMenuElement { |
|
175
|
|
|
return new OverflowMenuElement($placeholder, $actionId, $confirmDialog, $options); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
3 |
|
public function elementPlainText( |
|
179
|
|
|
string $text |
|
180
|
|
|
): PlainTextElement { |
|
181
|
3 |
|
return new PlainTextElement($text); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
public function elementPlainTextInput( |
|
185
|
|
|
string $actionId, |
|
186
|
|
|
string $placeholder = '', |
|
187
|
|
|
string $initialValue = '', |
|
188
|
|
|
bool $multiline = false, |
|
189
|
|
|
int $minLength = 1, |
|
190
|
|
|
int $maxLength = 3000 |
|
191
|
|
|
): PlainTextInputElement { |
|
192
|
|
|
return new PlainTextInputElement($actionId, $placeholder, $initialValue, $multiline, $minLength, $maxLength); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
public function elementRadioButtonGroup( |
|
196
|
|
|
string $actionId, |
|
197
|
|
|
ConfirmationDialogObject $confirmationDialog = null, |
|
198
|
|
|
OptionObject $initialOption = null, |
|
199
|
|
|
OptionObject ...$options |
|
200
|
|
|
): RadioButtonGroupElement { |
|
201
|
|
|
return new RadioButtonGroupElement($actionId, $confirmationDialog, $initialOption, ...$options); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
public function elementSelectExternal( |
|
205
|
|
|
string $placeholder, |
|
206
|
|
|
string $actionId, |
|
207
|
|
|
int $minQueryLength, |
|
208
|
|
|
OptionObject $initialOption = null, |
|
209
|
|
|
ConfirmationDialogObject $confirmDialog = null |
|
210
|
|
|
): SelectExternalElement { |
|
211
|
|
|
return new SelectExternalElement($placeholder, $actionId, $minQueryLength, $initialOption, $confirmDialog); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
public function elementSelectStatic( |
|
215
|
|
|
string $placeholder, |
|
216
|
|
|
string $actionId, |
|
217
|
|
|
OptionObject $initialOption = null, |
|
218
|
|
|
ConfirmationDialogObject $confirmDialog = null, |
|
219
|
|
|
OptionObject ...$options |
|
220
|
|
|
): SelectStaticElement { |
|
221
|
|
|
return new SelectStaticElement($placeholder, $actionId, $initialOption, $confirmDialog, ...$options); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
public function elementSelectStaticGroup( |
|
225
|
|
|
string $placeholder, |
|
226
|
|
|
string $actionId, |
|
227
|
|
|
OptionObject $initialOption = null, |
|
228
|
|
|
ConfirmationDialogObject $confirmDialog = null, |
|
229
|
|
|
OptionGroupObject ...$optionGroups |
|
230
|
|
|
): SelectStaticGroupElement { |
|
231
|
|
|
return new SelectStaticGroupElement($placeholder, $actionId, $initialOption, $confirmDialog, ...$optionGroups); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
public function elementSelectUserText( |
|
235
|
|
|
string $placeholder, |
|
236
|
|
|
string $actionId, |
|
237
|
|
|
string $initialUser, |
|
238
|
|
|
ConfirmationDialogObject $confirmDialog = null |
|
239
|
|
|
): SelectUserElement { |
|
240
|
|
|
return new SelectUserElement($placeholder, $actionId, $initialUser, $confirmDialog); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
//------------------------------------------------------------------------------------------------------------------ |
|
244
|
|
|
|
|
245
|
|
|
public function objectConfirmationDialog( |
|
246
|
|
|
string $title, |
|
247
|
|
|
TextElementInterface $text, |
|
248
|
|
|
string $confirm, |
|
249
|
|
|
string $deny |
|
250
|
|
|
): ConfirmationDialogObject { |
|
251
|
|
|
return new ConfirmationDialogObject($title, $text, $confirm, $deny); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
1 |
|
public function objectOptionGroup( |
|
255
|
|
|
string $label, |
|
256
|
|
|
OptionObject ...$options |
|
257
|
|
|
): OptionGroupObject { |
|
258
|
1 |
|
return new OptionGroupObject($label, ...$options); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
1 |
|
public function objectOption( |
|
262
|
|
|
string $text, |
|
263
|
|
|
string $value, |
|
264
|
|
|
string $url = '' |
|
265
|
|
|
): OptionObject { |
|
266
|
1 |
|
return new OptionObject($text, $value, $url); |
|
267
|
|
|
} |
|
268
|
|
|
} |
|
269
|
|
|
|