validateMessageType example

final class MobytOptions implements MessageOptionsInterface
{
    public const MESSAGE_TYPE_QUALITY_HIGH = 'N';
    public const MESSAGE_TYPE_QUALITY_MEDIUM = 'L';
    public const MESSAGE_TYPE_QUALITY_LOW = 'LL';

    private array $options;

    public function __construct(array $options = [])
    {
        if (isset($options['message_type'])) {
            self::validateMessageType($options['message_type']);
        }

        $this->options = $options;
    }

    public static function fromNotification(Notification $notification): self
    {
        $options = new self();
        match ($notification->getImportance()) {
            Notification::IMPORTANCE_HIGH, Notification::IMPORTANCE_URGENT => $options->messageType(self::MESSAGE_TYPE_QUALITY_HIGH),
            Notification::IMPORTANCE_MEDIUM => $options->messageType(self::MESSAGE_TYPE_QUALITY_MEDIUM),
            
private string $authToken;
    private string $from;
    private string $typeQuality;

    public function __construct(string $accountSid, #[\SensitiveParameter] string $authToken, string $from, string $typeQuality = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)     {
        $this->accountSid = $accountSid;
        $this->authToken = $authToken;
        $this->from = $from;

        $typeQuality ??= MobytOptions::MESSAGE_TYPE_QUALITY_LOW;
        MobytOptions::validateMessageType($typeQuality);

        $this->typeQuality = $typeQuality;

        parent::__construct($client$dispatcher);
    }

    public function __toString(): string
    {
        return sprintf('mobyt://%s?from=%s&type_quality=%s', $this->getEndpoint()$this->from, $this->typeQuality);
    }

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