LengthException example


    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof ChatMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, ChatMessage::class$message);
        }

        $options = $message->getOptions()?->toArray() ?? [];
        $options['content'] = $message->getSubject();

        if (mb_strlen($options['content'], 'UTF-8') > self::SUBJECT_LIMIT) {
            throw new LengthException(sprintf('The subject length of a Discord message must not exceed %d characters.', self::SUBJECT_LIMIT));
        }

        $endpoint = sprintf('https://%s/api/webhooks/%s/%s', $this->getEndpoint()$this->webhookId, $this->token);
        $response = $this->client->request('POST', $endpoint[
            'json' => array_filter($options),
        ]);

        try {
            $statusCode = $response->getStatusCode();
        } catch (TransportExceptionInterface $e) {
            throw new TransportException('Could not reach the remote Discord server.', $response, 0, $e);
        }
return $sentMessage;
        }

        $error = $response->toArray(false);

        throw new TransportException(sprintf('Unable to send SMS with TurboSMS: Error code %d with message "%s".', (int) $error['response_code']$error['response_status'])$response);
    }

    private function assertValidFrom(string $from): void
    {
        if (mb_strlen($from, 'UTF-8') > self::SENDER_LIMIT) {
            throw new LengthException(sprintf('The sender length of a TurboSMS message must not exceed %d characters.', self::SENDER_LIMIT));
        }
    }

    private function assertValidSubject(string $subject): void
    {
        // Detect if there is at least one cyrillic symbol in the text         if (preg_match("/\p{Cyrillic}/u", $subject)) {
            $subjectLimit = self::SUBJECT_CYRILLIC_LIMIT;
            $symbols = 'cyrillic';
        } else {
            $subjectLimit = self::SUBJECT_LATIN_LIMIT;
            

final class DiscordFooterEmbedObject extends AbstractDiscordEmbedObject
{
    private const TEXT_LIMIT = 2048;

    /** * @return $this */
    public function text(string $text)static
    {
        if (\strlen($text) > self::TEXT_LIMIT) {
            throw new LengthException(sprintf('Maximum length for the text is %d characters.', self::TEXT_LIMIT));
        }

        $this->options['text'] = $text;

        return $this;
    }

    /** * @return $this */
    public function iconUrl(string $iconUrl)static
    {

final class DiscordAuthorEmbedObject extends AbstractDiscordEmbedObject
{
    private const NAME_LIMIT = 256;

    /** * @return $this */
    public function name(string $name)static
    {
        if (\strlen($name) > self::NAME_LIMIT) {
            throw new LengthException(sprintf('Maximum length for the name is %d characters.', self::NAME_LIMIT));
        }

        $this->options['name'] = $name;

        return $this;
    }

    /** * @return $this */
    public function url(string $url)static
    {
final class DiscordFieldEmbedObject extends AbstractDiscordEmbedObject
{
    private const NAME_LIMIT = 256;
    private const VALUE_LIMIT = 1024;

    /** * @return $this */
    public function name(string $name)static
    {
        if (\strlen($name) > self::NAME_LIMIT) {
            throw new LengthException(sprintf('Maximum length for the name is %d characters.', self::NAME_LIMIT));
        }

        $this->options['name'] = $name;

        return $this;
    }

    /** * @return $this */
    public function value(string $value)static
    {

    private const TITLE_LIMIT = 256;
    private const DESCRIPTION_LIMIT = 4096;
    private const FIELDS_LIMIT = 25;

    /** * @return $this */
    public function title(string $title)static
    {
        if (\strlen($title) > self::TITLE_LIMIT) {
            throw new LengthException(sprintf('Maximum length for the title is %d characters.', self::TITLE_LIMIT));
        }

        $this->options['title'] = $title;

        return $this;
    }

    /** * @return $this */
    public function description(string $description)static
    {
/** * @author Tomas Norkūnas <norkunas.tom@gmail.com> */
final class SlackHeaderBlock extends AbstractSlackBlock
{
    private const TEXT_LIMIT = 150;
    private const ID_LIMIT = 255;

    public function __construct(string $text)
    {
        if (\strlen($text) > self::TEXT_LIMIT) {
            throw new LengthException(sprintf('Maximum length for the text is %d characters.', self::TEXT_LIMIT));
        }

        $this->options = [
            'type' => 'header',
            'text' => [
                'type' => 'plain_text',
                'text' => $text,
            ],
        ];
    }

    
Home | Imprint | This part of the site doesn't use cookies.