1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** @noinspection DuplicatedCode, UnusedConstructorDependenciesInspection */ |
4
|
|
|
|
5
|
|
|
declare(strict_types=1); |
6
|
|
|
|
7
|
|
|
/* |
8
|
|
|
* This file is part of the zibios/sharep. |
9
|
|
|
* |
10
|
|
|
* (c) Zbigniew Ślązak |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace App\Slack\MessageBuilder\Element; |
14
|
|
|
|
15
|
|
|
use App\Slack\MessageBuilder\Enum\MessageTypeEnum; |
16
|
|
|
use App\Slack\MessageBuilder\MessageJsonSerializeTrait; |
17
|
|
|
use App\Slack\MessageBuilder\Object\ConfirmationDialogObject; |
18
|
|
|
use App\Slack\MessageBuilder\Object\OptionObject; |
19
|
|
|
|
20
|
|
|
class SelectStaticElement implements SectionBlockElementInterface, ActionsBlockElementInterface, InputBlockElementInterface |
21
|
|
|
{ |
22
|
|
|
use MessageJsonSerializeTrait; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
private $type; |
26
|
|
|
/** @var PlainTextElement */ |
27
|
|
|
private $placeholder; |
28
|
|
|
/** @var string */ |
29
|
|
|
private $actionId; |
30
|
|
|
/** @var OptionObject */ |
31
|
|
|
private $initialOption; |
32
|
|
|
/** @var ConfirmationDialogObject */ |
33
|
|
|
private $confirmDialog; |
34
|
|
|
/** @var array|OptionObject[] */ |
35
|
|
|
private $options; |
36
|
|
|
|
37
|
|
|
public function __construct(string $placeholder, string $actionId, OptionObject $initialOption = null, ConfirmationDialogObject $confirmDialog = null, OptionObject ...$options) |
38
|
|
|
{ |
39
|
|
|
if (\strlen($placeholder) > 150) { |
40
|
|
|
throw new \InvalidArgumentException('$text too long!'); |
41
|
|
|
} |
42
|
|
|
if (\strlen($actionId) > 255) { |
43
|
|
|
throw new \InvalidArgumentException('$actionId too long!'); |
44
|
|
|
} |
45
|
|
|
if (\count($options) > 100) { |
46
|
|
|
throw new \InvalidArgumentException('$options too long!'); |
47
|
|
|
} |
48
|
|
|
if (0 === \count($options)) { |
49
|
|
|
throw new \InvalidArgumentException('$url too short!'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$this->type = MessageTypeEnum::ELEMENT_SELECT_STATIC; |
53
|
|
|
$this->placeholder = new PlainTextElement($placeholder); |
54
|
|
|
$this->actionId = $actionId; |
55
|
|
|
$this->initialOption = $initialOption; |
56
|
|
|
$this->confirmDialog = $confirmDialog; |
57
|
|
|
$this->options = $options; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|