UnsupportedSchemeException example

/** * @author Adrian Nguyen <vuphuong87@gmail.com> */
final class MessageMediaTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): MessageMediaTransport
    {
        $scheme = $dsn->getScheme();

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

        $apiKey = $this->getUser($dsn);
        $apiSecret = $this->getPassword($dsn);
        $from = $dsn->getOption('from');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new MessageMediaTransport($apiKey$apiSecret$from$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    

final class TermiiTransportFactory extends AbstractTransportFactory
{
    private const TRANSPORT_SCHEME = 'termii';

    public function create(Dsn $dsn): TermiiTransport
    {
        $scheme = $dsn->getScheme();

        if (self::TRANSPORT_SCHEME !== $scheme) {
            throw new UnsupportedSchemeException($dsn, self::TRANSPORT_SCHEME, $this->getSupportedSchemes());
        }

        $apiKey = $this->getUser($dsn);
        $from = $dsn->getRequiredOption('from');
        $channel = $dsn->getRequiredOption('channel');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new TermiiTransport($apiKey$from$channel$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    
/** * @author Mohammad Emran Hasan <phpfour@gmail.com> */
final class ZulipTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): ZulipTransport
    {
        $scheme = $dsn->getScheme();

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

        $email = $this->getUser($dsn);
        $token = $this->getPassword($dsn);
        $channel = $dsn->getRequiredOption('channel');
        $host = $dsn->getHost();
        $port = $dsn->getPort();

        return (new ZulipTransport($email$token$channel$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    
/** * @author Thibault Buathier <thibault.buathier@gmail.com> */
final class SmsFactorTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): SmsFactorTransport
    {
        $scheme = $dsn->getScheme();

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

        $tokenApi = $this->getUser($dsn);
        $sender = $dsn->getOption('sender');
        $pushType = $this->getPushType($dsn);

        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new SmsFactorTransport($tokenApi$sender$pushType$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    
if ('mandrill+https' === $scheme || 'mandrill' === $scheme) {
            return (new MandrillHttpTransport($user$this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
        }

        if ('mandrill+smtp' === $scheme || 'mandrill+smtps' === $scheme) {
            $password = $this->getPassword($dsn);

            return new MandrillSmtpTransport($user$password$this->dispatcher, $this->logger);
        }

        throw new UnsupportedSchemeException($dsn, 'mandrill', $this->getSupportedSchemes());
    }

    protected function getSupportedSchemes(): array
    {
        return ['mandrill', 'mandrill+api', 'mandrill+https', 'mandrill+smtp', 'mandrill+smtps'];
    }
}
/** * @author gnito-org <https://github.com/gnito-org> */
final class RingCentralTransportFactory extends AbstractTransportFactory
{
    private const TRANSPORT_SCHEME = 'ringcentral';

    public function create(Dsn $dsn): RingCentralTransport
    {
        $scheme = $dsn->getScheme();
        if (self::TRANSPORT_SCHEME !== $scheme) {
            throw new UnsupportedSchemeException($dsn, self::TRANSPORT_SCHEME, $this->getSupportedSchemes());
        }
        $apiKey = $this->getUser($dsn);
        $from = $dsn->getRequiredOption('from');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new RingCentralTransport($apiKey$from$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        
/** * @author Emanuele Panzeri <thepanz@gmail.com> */
final class MattermostTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): MattermostTransport
    {
        $scheme = $dsn->getScheme();

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

        $path = $dsn->getPath();
        $token = $this->getUser($dsn);
        $channel = $dsn->getRequiredOption('channel');
        $host = $dsn->getHost();
        $port = $dsn->getPort();

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

    
/** * @author gnito-org <https://github.com/gnito-org> */
final class ClickSendTransportFactory extends AbstractTransportFactory
{
    private const TRANSPORT_SCHEME = 'clicksend';

    public function create(Dsn $dsn): ClickSendTransport
    {
        $scheme = $dsn->getScheme();
        if (self::TRANSPORT_SCHEME !== $scheme) {
            throw new UnsupportedSchemeException($dsn, self::TRANSPORT_SCHEME, $this->getSupportedSchemes());
        }
        $apiUsername = $this->getUser($dsn);
        $apiKey = $this->getPassword($dsn);
        $from = $dsn->getOption('from');
        $source = $dsn->getOption('source');
        $listId = $dsn->getOption('list_id');
        $fromEmail = $dsn->getOption('from_email');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new ClickSendTransport($apiUsername$apiKey$from$source$listId$fromEmail$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }


            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);
        }

        throw new UnsupportedSchemeException($dsn, 'infobip', $this->getSupportedSchemes());
    }

    protected function getSupportedSchemes(): array
    {
        return ['infobip', 'infobip+api', 'infobip+smtp', 'infobip+smtps'];
    }
}
/** * @author Vasilij Duško <vasilij@prado.lt> */
final class MessageBirdTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): MessageBirdTransport
    {
        $scheme = $dsn->getScheme();

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

        $token = $this->getUser($dsn);
        $from = $dsn->getRequiredOption('from');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new MessageBirdTransport($token$from$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
/** * @author Bastien Durand <bdurand-dev@outlook.com> */
final class MobytTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): MobytTransport
    {
        $scheme = $dsn->getScheme();

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

        $accountSid = $this->getUser($dsn);
        $authToken = $this->getPassword($dsn);
        $from = $dsn->getRequiredOption('from');
        $typeQuality = $dsn->getOption('type_quality');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new MobytTransport($accountSid$authToken$from$typeQuality$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    


    /** * @dataProvider messageWhereSchemeIsPartOfSchemeToPackageMapProvider */
    public function testMessageWhereSchemeIsPartOfSchemeToPackageMap(string $scheme, string $package)
    {
        $dsn = new Dsn($scheme, 'localhost');

        $this->assertSame(
            sprintf('Unable to send emails via "%s" as the bridge is not installed. Try running "composer require %s".', $scheme$package),
            (new UnsupportedSchemeException($dsn))->getMessage()
        );
    }

    public static function messageWhereSchemeIsPartOfSchemeToPackageMapProvider(): \Generator
    {
        yield ['brevo', 'symfony/brevo-mailer'];
        yield ['gmail', 'symfony/google-mailer'];
        yield ['infobip', 'symfony/infobip-mailer'];
        yield ['mailersend', 'symfony/mailersend-mailer'];
        yield ['mailgun', 'symfony/mailgun-mailer'];
        yield ['mailjet', 'symfony/mailjet-mailer'];
        
/** * @author Vasilij Duško <vasilij@prado.lt> */
final class TelnyxTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): TelnyxTransport
    {
        $scheme = $dsn->getScheme();

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

        $apiKey = $this->getUser($dsn);
        $from = $dsn->getRequiredOption('from');
        $messagingProfileId = $dsn->getOption('messaging_profile_id');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new TelnyxTransport($apiKey$from$messagingProfileId$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    
/** * @author Jeroen Spee <https://github.com/Jeroeny> */
final class FirebaseTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): FirebaseTransport
    {
        $scheme = $dsn->getScheme();

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

        $token = sprintf('%s:%s', $this->getUser($dsn)$this->getPassword($dsn));
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

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

    protected function getSupportedSchemes(): array
    {
        

final class BandwidthTransportFactory extends AbstractTransportFactory
{
    private const TRANSPORT_SCHEME = 'bandwidth';

    public function create(Dsn $dsn): BandwidthTransport
    {
        $scheme = $dsn->getScheme();

        if (self::TRANSPORT_SCHEME !== $scheme) {
            throw new UnsupportedSchemeException($dsn, self::TRANSPORT_SCHEME, $this->getSupportedSchemes());
        }

        $username = $this->getUser($dsn);
        $password = $this->getPassword($dsn);
        $from = $dsn->getRequiredOption('from');
        $accountId = $dsn->getRequiredOption('account_id');
        $applicationId = $dsn->getRequiredOption('application_id');
        $priority = $dsn->getOption('priority');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

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