getRequiredOption example


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

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

        $login = $this->getUser($dsn);
        $password = $this->getPassword($dsn);
        $phone = $dsn->getRequiredOption('phone');

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

        return (new FreeMobileTransport($login$password$phone$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        return ['freemobile'];
    }
}
public function create(Dsn $dsn): PlivoTransport
    {
        $scheme = $dsn->getScheme();

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

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

        return (new PlivoTransport($authId$authToken$from$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        return [self::TRANSPORT_SCHEME];
    }
}

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

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

        $login = $this->getUser($dsn);
        $token = $this->getPassword($dsn);
        $from = $dsn->getRequiredOption('from');

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

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

    protected function getSupportedSchemes(): array
    {
        return ['lightsms'];
    }
}
final class DiscordTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): DiscordTransport
    {
        $scheme = $dsn->getScheme();

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

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

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

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

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

    protected function getSupportedSchemes(): array
    {
        return ['zulip'];
    }
}
public function create(Dsn $dsn): FakeChatEmailTransport|FakeChatLoggerTransport
    {
        $scheme = $dsn->getScheme();

        if ('fakechat+email' === $scheme) {
            if (null === $this->mailer) {
                $this->throwMissingDependencyException($scheme, MailerInterface::class, 'symfony/mailer');
            }

            $mailerTransport = $dsn->getHost();
            $to = $dsn->getRequiredOption('to');
            $from = $dsn->getRequiredOption('from');

            return (new FakeChatEmailTransport($this->mailer, $to$from))->setHost($mailerTransport);
        }

        if ('fakechat+logger' === $scheme) {
            if (null === $this->logger) {
                $this->throwMissingDependencyException($scheme, LoggerInterface::class, 'psr/log');
            }

            return new FakeChatLoggerTransport($this->logger);
        }

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

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

        $username = $this->getUser($dsn);
        $password = $this->getPassword($dsn);
        $sender = $dsn->getRequiredOption('sender');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new KazInfoTehTransport($username$password$sender$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        return ['kaz-info-teh'];
    }
}

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

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

        $login = $dsn->getUser();
        $password = $dsn->getPassword();
        $from = $dsn->getRequiredOption('from');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();

        return (new SmscTransport($login$password$from$this->client, $this->dispatcher))->setHost($host);
    }

    protected function getSupportedSchemes(): array
    {
        return ['smsc'];
    }
}
public function create(Dsn $dsn): SendinblueTransport
    {
        trigger_deprecation('symfony/sendinblue-notifier', '6.3', 'The "%s" class is deprecated, use "%s" instead.', SendinblueTransport::class, BrevoTransport::class);

        $scheme = $dsn->getScheme();

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

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

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

    protected function getSupportedSchemes(): array
    {
        return ['sendinblue'];
    }
}
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
    {
        return ['messagebird'];
    }
}

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

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

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

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

    protected function getSupportedSchemes(): array
    {
        return ['sinch'];
    }
}
public function create(Dsn $dsn): SendberryTransport
    {
        $scheme = $dsn->getScheme();

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

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

        return (new SendberryTransport($this->getUser($dsn)$this->getPassword($dsn)$dsn->getRequiredOption('auth_key')$dsn->getRequiredOption('from')$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        return ['sendberry'];
    }
}
final class EngagespotTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): EngagespotTransport
    {
        $scheme = $dsn->getScheme();

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

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

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

    protected function getSupportedSchemes(): array
    {
        return ['engagespot'];
    }
}
'default-value',
        ];
    }

    /** * @dataProvider getRequiredOptionProvider */
    public function testGetRequiredOption(string $expectedValue, string $options, string $option)
    {
        $dsn = new Dsn(sprintf('scheme://localhost?%s', $options));

        $this->assertSame($expectedValue$dsn->getRequiredOption($option));
    }

    public static function getRequiredOptionProvider(): iterable
    {
        yield [
            'value',
            'with_value=value',
            'with_value',
        ];

        yield [
            
'default-value',
        ];
    }

    /** * @dataProvider getRequiredOptionProvider */
    public function testGetRequiredOption(string $expectedValue, string $options, string $option)
    {
        $dsn = new Dsn(sprintf('scheme://localhost?%s', $options));

        $this->assertSame($expectedValue$dsn->getRequiredOption($option));
    }

    public static function getRequiredOptionProvider(): iterable
    {
        yield [
            'value',
            'with_value=value',
            'with_value',
        ];

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