59 lines
1.5 KiB
PHP
59 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Slack;
|
|
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Slack\Exceptions\SlackSyntaxException;
|
|
|
|
/**
|
|
* Class BlockKit - Slack Blockit Objects
|
|
*
|
|
* @notes
|
|
* + callback_id is used to identify the source of any action (modal). (Message blocks do not have a callback_id, accept in legacy attachments).
|
|
* eg: hometab, add_product, ask_modal
|
|
* + block_id is used to identify the sub action(s) of any action (modal). (Messages with blocks can have a block_id, we need to use this to determine what to do.)
|
|
* eg: multiple blocks (list of something)
|
|
* + action_id is used to identify the action that was initiated
|
|
* eg: view, edit, review
|
|
* + value is the value of the action_id
|
|
* eg: 5 (question #), yes, no, skip, abort
|
|
*
|
|
* @package Slack
|
|
*/
|
|
abstract class BlockKit implements \JsonSerializable,\Countable
|
|
{
|
|
protected Collection $_data;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->_data = collect();
|
|
}
|
|
|
|
public function __get($key) {
|
|
return $this->_data->get($key);
|
|
}
|
|
|
|
public function __set(string $key,$value) {
|
|
return $this->_data->put($key,$value);
|
|
}
|
|
|
|
public function count()
|
|
{
|
|
return $this->_data->count();
|
|
}
|
|
|
|
public function jsonSerialize()
|
|
{
|
|
return $this->_data;
|
|
}
|
|
|
|
protected function validate(string $key,$value)
|
|
{
|
|
if (Arr::get(static::LIMITS,$key) && (strlen($value) > static::LIMITS[$key]))
|
|
throw new SlackSyntaxException(sprintf('%s must be %d chars or less for buttons %s',$key,static::LIMITS[$key],get_class($this)));
|
|
|
|
return $value;
|
|
}
|
|
} |