2021-08-06 02:22:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Slack;
|
|
|
|
|
2022-01-18 03:34:57 +00:00
|
|
|
use Illuminate\Support\Arr;
|
2021-08-06 02:22:22 +00:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
2022-09-04 02:18:11 +00:00
|
|
|
use Slack\Exceptions\SlackSyntaxException;
|
|
|
|
|
2021-08-06 02:22:22 +00:00
|
|
|
/**
|
|
|
|
* Class BlockKit - Slack Blockit Objects
|
|
|
|
*
|
|
|
|
* @package Slack
|
|
|
|
*/
|
2022-01-18 03:34:57 +00:00
|
|
|
abstract class BlockKit implements \JsonSerializable
|
2021-08-06 02:22:22 +00:00
|
|
|
{
|
|
|
|
protected Collection $_data;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->_data = collect();
|
|
|
|
}
|
|
|
|
|
2022-01-18 03:34:57 +00:00
|
|
|
public function __get($key) {
|
|
|
|
return $this->_data->get($key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __set(string $key,$value) {
|
|
|
|
return $this->_data->put($key,$value);
|
|
|
|
}
|
|
|
|
|
2021-08-10 03:48:59 +00:00
|
|
|
public function count()
|
2021-08-06 02:22:22 +00:00
|
|
|
{
|
2021-08-10 03:48:59 +00:00
|
|
|
return $this->_data->count();
|
2021-08-06 02:22:22 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 03:48:59 +00:00
|
|
|
public function jsonSerialize()
|
2021-08-06 02:22:22 +00:00
|
|
|
{
|
2021-08-10 03:48:59 +00:00
|
|
|
return $this->_data;
|
2021-08-06 02:22:22 +00:00
|
|
|
}
|
2022-01-18 03:34:57 +00:00
|
|
|
|
|
|
|
protected function validate(string $key,$value)
|
|
|
|
{
|
|
|
|
if (Arr::get(static::LIMITS,$key) && (strlen($value) > static::LIMITS[$key]))
|
2022-09-04 02:18:11 +00:00
|
|
|
throw new SlackSyntaxException(sprintf('%s must be %d chars or less for buttons %s',$key,static::LIMITS[$key],get_class($this)));
|
2022-01-18 03:34:57 +00:00
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|