1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** @noinspection 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\ButtonStyleEnum; |
16
|
|
|
use App\Slack\MessageBuilder\Enum\MessageTypeEnum; |
17
|
|
|
use App\Slack\MessageBuilder\MessageJsonSerializeTrait; |
18
|
|
|
use App\Slack\MessageBuilder\Object\ConfirmationDialogObject; |
19
|
|
|
|
20
|
|
|
class ButtonElement implements SectionBlockElementInterface, ActionsBlockElementInterface |
21
|
|
|
{ |
22
|
|
|
use MessageJsonSerializeTrait; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
private $type; |
26
|
|
|
/** @var PlainTextElement */ |
27
|
|
|
private $text; |
28
|
|
|
/** @var string */ |
29
|
|
|
private $actionId; |
30
|
|
|
/** @var ButtonStyleEnum|null */ |
31
|
|
|
private $style; |
32
|
|
|
/** @var ConfirmationDialogObject|null */ |
33
|
|
|
private $confirm; |
34
|
|
|
/** @var string */ |
35
|
|
|
private $value; |
36
|
|
|
/** @var string */ |
37
|
|
|
private $url; |
38
|
|
|
|
39
|
2 |
|
public function __construct(string $text, string $actionId, ButtonStyleEnum $style = null, ConfirmationDialogObject $confirm = null, string $value = '', string $url = '') |
40
|
|
|
{ |
41
|
2 |
|
if (\strlen($text) > 75) { |
42
|
|
|
throw new \InvalidArgumentException('$text too long!'); |
43
|
|
|
} |
44
|
2 |
|
if (\strlen($actionId) > 255) { |
45
|
|
|
throw new \InvalidArgumentException('$actionId too long!'); |
46
|
|
|
} |
47
|
2 |
|
if (\strlen($value) > 2000) { |
48
|
|
|
throw new \InvalidArgumentException('$value too long!'); |
49
|
|
|
} |
50
|
2 |
|
if (\strlen($url) > 3000) { |
51
|
|
|
throw new \InvalidArgumentException('$url too long!'); |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
$this->type = MessageTypeEnum::ELEMENT_BUTTON; |
55
|
2 |
|
$this->text = new PlainTextElement($text); |
56
|
2 |
|
$this->actionId = $actionId; |
57
|
2 |
|
$this->style = $style; |
58
|
2 |
|
$this->confirm = $confirm; |
59
|
2 |
|
$this->value = $value; |
60
|
2 |
|
$this->url = $url; |
61
|
2 |
|
} |
62
|
|
|
} |
63
|
|
|
|