IncompleteDsnException example

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

        $from = $message->getFrom() ?: $this->from;

        if (!preg_match('/^[+]+[1-9][0-9]{9,14}$/', $from)) {
            if ('' === $from) {
                throw new IncompleteDsnException('This phone number is invalid.');
            } elseif ('' !== $from && null === $this->messagingProfileId) {
                throw new IncompleteDsnException('The sending messaging profile must be specified.');
            }

            if (!preg_match('/^[a-zA-Z0-9 ]+$/', $from)) {
                throw new IncompleteDsnException('The Sender ID is invalid.');
            }
        }

        $endpoint = sprintf('https://%s/v2/messages', $this->getEndpoint());
        $response = $this->client->request('POST', $endpoint[
            


    protected function getSupportedSchemes(): array
    {
        return ['pagerduty'];
    }

    private function getHost(Dsn $dsn): string
    {
        $host = $dsn->getHost();
        if ('default' === $host) {
            throw new IncompleteDsnException('Host is not set.', 'pagerduty://default');
        }

        if (!str_ends_with($host, '.pagerduty.com')) {
            throw new IncompleteDsnException('Host must be in format: "subdomain.pagerduty.com".', 'pagerduty://'.$host);
        }

        return $host;
    }
}
public function create(Dsn $dsn): MicrosoftTeamsTransport
    {
        $scheme = $dsn->getScheme();

        if ('microsoftteams' !== $scheme) {
            throw new UnsupportedSchemeException($dsn, 'microsoftteams', $this->getSupportedSchemes());
        }

        $path = $dsn->getPath();

        if (null === $path) {
            throw new IncompleteDsnException('Path is not set.', 'microsoftteams://'.$dsn->getHost());
        }

        $host = $dsn->getHost();
        $port = $dsn->getPort();

        return (new MicrosoftTeamsTransport($path$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        return ['microsoftteams'];
    }
$scheme = $dsn->getScheme();

        if ('twitter' !== $scheme) {
            throw new UnsupportedSchemeException($dsn, 'twitter', $this->getSupportedSchemes());
        }

        $apiKey = $this->getUser($dsn);
        [$apiSecret$accessToken$accessSecret] = explode(':', $this->getPassword($dsn)) + [1 => null, null, null];

        foreach (['API Key' => $apiKey, 'API Key Secret' => $apiSecret, 'Access Token' => $accessToken, 'Access Token Secret' => $accessSecret] as $name => $key) {
            if (!$key) {
                throw new IncompleteDsnException($name.' is missing.', 'twitter://'.$dsn->getHost());
            }
        }

        return (new TwitterTransport($apiKey$apiSecret$accessToken$accessSecret$this->client, $this->dispatcher))
            ->setHost('default' === $dsn->getHost() ? null : $dsn->getHost())
            ->setPort($dsn->getPort());
    }

    protected function getSupportedSchemes(): array
    {
        return ['twitter'];
    }
return (new TelegramTransport($token$channel$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        return ['telegram'];
    }

    private function getToken(Dsn $dsn): string
    {
        if (null === $dsn->getUser() && null === $dsn->getPassword()) {
            throw new IncompleteDsnException('Missing token.', 'telegram://'.$dsn->getHost());
        }

        if (null === $dsn->getPassword()) {
            throw new IncompleteDsnException('Malformed token.', 'telegram://'.$dsn->getHost());
        }

        return sprintf('%s:%s', $dsn->getUser()$dsn->getPassword());
    }
}
protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$message instanceof SmsMessage) {
            throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class$message);
        }

        $from = $message->getFrom() ?: $this->from;

        if (!preg_match('/^[+]+[1-9][0-9]{9,14}$/', $from)) {
            if ('' === $from) {
                throw new IncompleteDsnException('This phone number is invalid.');
            }

            if (!preg_match('/^[a-zA-Z0-9 ]+$/', $from)) {
                throw new IncompleteDsnException('The Sender ID is invalid.');
            }
        }

        $endpoint = sprintf('https://%s/SMS/SEND', $this->getEndpoint());
        $response = $this->client->request('POST', $endpoint[
            'json' => [
                'from' => $from,
                


    protected function getSupportedSchemes(): array
    {
        return ['zendesk'];
    }

    private function getHost(Dsn $dsn): string
    {
        $host = $dsn->getHost();
        if ('default' === $host) {
            throw new IncompleteDsnException('Host is not set.', 'zendesk://default');
        }

        if (!str_ends_with($host, '.zendesk.com')) {
            throw new IncompleteDsnException('Host must be in format: "subdomain.zendesk.com".', 'zendesk://'.$dsn->getHost());
        }

        return $host;
    }
}
final class InfobipTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): TransportInterface
    {
        $schema = $dsn->getScheme();
        $apiKey = $this->getUser($dsn);

        if ('infobip+api' === $schema) {
            $host = $dsn->getHost();
            if ('default' === $host) {
                throw new IncompleteDsnException('Infobip mailer for API DSN must contain a host.');
            }

            return (new InfobipApiTransport($apiKey$this->client, $this->dispatcher, $this->logger))
                ->setHost($host)
            ;
        }

        if (\in_array($schema['infobip+smtp', 'infobip+smtps', 'infobip'], true)) {
            return new InfobipSmtpTransport($apiKey$this->dispatcher, $this->logger);
        }

        

        return \in_array($dsn->getScheme()$this->getSupportedSchemes());
    }

    /** * @return string[] */
    abstract protected function getSupportedSchemes(): array;

    protected function getUser(Dsn $dsn): string
    {
        return $dsn->getUser() ?? throw new IncompleteDsnException('User is not set.', $dsn->getScheme().'://'.$dsn->getHost());
    }

    protected function getPassword(Dsn $dsn): string
    {
        return $dsn->getPassword() ?? throw new IncompleteDsnException('Password is not set.', $dsn->getOriginalDsn());
    }
}

        if ('mercure' !== $dsn->getScheme()) {
            throw new UnsupportedSchemeException($dsn, 'mercure', $this->getSupportedSchemes());
        }

        $hubId = $dsn->getHost();
        $topic = $dsn->getOption('topic');

        try {
            $hub = $this->registry->getHub($hubId);
        } catch (InvalidArgumentException) {
            throw new IncompleteDsnException(sprintf('Hub "%s" not found. Did you mean one of: "%s"?', $hubIdimplode('", "', array_keys($this->registry->all()))));
        }

        return new MercureTransport($hub$hubId$topic);
    }

    protected function getSupportedSchemes(): array
    {
        return ['mercure'];
    }
}


    public function supports(Dsn $dsn): bool
    {
        return \in_array($dsn->getScheme()$this->getSupportedSchemes());
    }

    abstract protected function getSupportedSchemes(): array;

    protected function getUser(Dsn $dsn): string
    {
        return $dsn->getUser() ?? throw new IncompleteDsnException('User is not set.');
    }

    protected function getPassword(Dsn $dsn): string
    {
        return $dsn->getPassword() ?? throw new IncompleteDsnException('Password is not set.');
    }
}

        return \in_array($dsn->getScheme()$this->getSupportedSchemes(), true);
    }

    /** * @return string[] */
    abstract protected function getSupportedSchemes(): array;

    protected function getUser(Dsn $dsn): string
    {
        return $dsn->getUser() ?? throw new IncompleteDsnException('User is not set.', $dsn->getScheme().'://'.$dsn->getHost());
    }

    protected function getPassword(Dsn $dsn): string
    {
        return $dsn->getPassword() ?? throw new IncompleteDsnException('Password is not set.', $dsn->getOriginalDsn());
    }
}
Home | Imprint | This part of the site doesn't use cookies.