2022-08-23 17:48:09 +10:00

59 lines
1.3 KiB
PHP

<?php
namespace Slack\Blockkit\Blocks\Elements;
use \Exception;
use Slack\Blockkit\Element;
/**
* @note Overflow, select, and multi-select menus can only use plain_text objects,
* while radio buttons and checkboxes can use mrkdwn text objects
*/
final class Options extends Element
{
protected const LIMITS = [
'description' => 75,
'text' => 75,
'value' => 75,
'url' => 3000,
];
public function __construct(Text $text,string $value)
{
parent::__construct();
if (strlen($text->text) > self::LIMITS['text'])
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['text']));
$this->text = $text;
$this->value = $this->validate('value',$value);
}
public static function item(Text $text,string $value): self
{
return new self($text,$value);
}
/* OPTIONAL ITEMS */
public function description(Text $text): self
{
if ($text->type != 'plain_text')
throw new Exception(sprintf('Text must be plain_text not %s',$text->type));
if (strlen($text->text) > self::LIMITS['description'])
throw new Exception(sprintf('Text must be %d chars or less',self::LIMITS['description']));
$this->description = $text;
return $this;
}
public function url(string $string): self
{
$this->url = $this->validate('url',$string);
return $this;
}
}