/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackSectionBlock.php
79 строк
2 KB
Christophe VERGNE
[Notifier] [Slack] Add button block element and `emoji`/`verbatim` options to section block
31 май 2024, 09:33
31 май 2024, 09:33
e9b7954
Код
Авторство
О чём код?
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Notifier\Bridge\Slack\Block; /** * @author Fabien Potencier <fabien@symfony.com> */ final class SlackSectionBlock extends AbstractSlackBlock { public function __construct() { $this->options['type'] = 'section'; } /** * @return $this */ public function text(string $text, bool $markdown = true, bool $emoji = true, bool $verbatim = false): static { $this->options['text'] = [ 'type' => $markdown ? 'mrkdwn' : 'plain_text', 'text' => $text, ]; // verbatim is only available for markdown if ($markdown) { $this->options['text']['verbatim'] = $verbatim; } else { $this->options['text']['emoji'] = $emoji; } return $this; } /** * @return $this */ public function field(string $text, bool $markdown = true, bool $emoji = true, bool $verbatim = false): static { if (10 === \count($this->options['fields'] ?? [])) { throw new \LogicException('Maximum number of fields should not exceed 10.'); } $field = [ 'type' => $markdown ? 'mrkdwn' : 'plain_text', 'text' => $text, ]; // verbatim is only available for markdown if ($markdown) { $field['verbatim'] = $verbatim; } else { $field['emoji'] = $emoji; } $this->options['fields'][] = $field; return $this; } /** * @return $this */ public function accessory(SlackBlockElementInterface $element): static { $this->options['accessory'] = $element->toArray(); return $this; } }