66 lines
1.3 KiB
PHP
66 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Slack\Blockkit\Blocks;
|
|
|
|
use \Exception;
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Slack\Blockkit\Blocks;
|
|
use Slack\Blockkit\Blocks\Elements\{Button,MultiStaticSelect};
|
|
|
|
final class Actions extends Blocks
|
|
{
|
|
protected const LIMITS = [
|
|
'block_id' => 255, // @todo Should be unique for each message
|
|
];
|
|
|
|
private const MAX_ELEMENTS = 5;
|
|
|
|
private const VALID_ELEMENTS = [
|
|
Button::class,
|
|
MultiStaticSelect::class,
|
|
Blocks\Accessories\Overflow::class,
|
|
];
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
// Defaults
|
|
$this->type = 'actions';
|
|
}
|
|
|
|
public static function item(): self
|
|
{
|
|
return new self();
|
|
}
|
|
|
|
public function jsonSerialize()
|
|
{
|
|
if (! $this->elements)
|
|
throw new Exception('Must define at least 1 element');
|
|
|
|
return parent::jsonSerialize();
|
|
}
|
|
|
|
/* OPTIONAL ITEMS */
|
|
|
|
public function block_id(string $string): self
|
|
{
|
|
$this->block_id = $this->validate('block_id',$string);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function elements(Collection $collection): self
|
|
{
|
|
if (count($collection) > self::MAX_ELEMENTS)
|
|
throw new Exception(sprintf('Can only have maximum %d elements',self::MAX_ELEMENTS));
|
|
|
|
// @todo Check that a valid element is added. https://api.slack.com/reference/block-kit/blocks#actions
|
|
|
|
$this->elements = $collection;
|
|
|
|
return $this;
|
|
}
|
|
} |