slack/src/Blockkit/Blocks/Elements/ExternalSelect.php

77 lines
1.5 KiB
PHP

<?php
namespace Slack\Blockkit\Blocks\Elements;
use \Exception;
use Slack\Blockkit\Element;
final class ExternalSelect extends Element
{
protected const LIMITS = [
'action_id' => 255,
'placeholder' => 150,
];
/**
* @param Text $placeholder
* @param string $action_id
* @throws Exception
*/
public function __construct(Text $placeholder,string $action_id)
{
parent::__construct();
// Defaults
$this->type = 'external_select';
if ($placeholder->type != 'plain_text')
throw new Exception(sprintf('Text must be plain_text not %s',$placeholder->type));
if (strlen($placeholder->text) > self::LIMITS['placeholder'])
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['placeholder']));
$this->placeholder = $placeholder;
$this->action_id = $this->validate('action_id',$action_id);
}
public static function item(Text $placeholder,string $action_id): self
{
return new self($placeholder,$action_id);
}
/* OPTIONAL ITEMS */
public function confirm(Confirm $confirm): self
{
$this->confirm = $confirm;
return $this;
}
// @note only 1 element in a view can have this set to true
public function focus_on_load(bool $bool): self
{
$this->focus_on_load = $bool;
return $this;
}
public function initial_option(string $option): self
{
$this->initial_option = $option;
return $this;
}
public function min_query_length(int $int): self
{
if ($int < 1)
throw new Exception('Minimum 1 options must be configured');
$this->min_query_length = $int;
return $this;
}
}