SendgridApiTransport example

new Dsn('sendgrid+smtp', 'example.com'),
            true,
        ];
    }

    public static function createProvider(): iterable
    {
        $logger = new NullLogger();

        yield [
            new Dsn('sendgrid+api', 'default', self::USER),
            new SendgridApiTransport(self::USER, new MockHttpClient(), null, $logger),
        ];

        yield [
            new Dsn('sendgrid+api', 'example.com', self::USER, '', 8080),
            (new SendgridApiTransport(self::USER, new MockHttpClient(), null, $logger))->setHost('example.com')->setPort(8080),
        ];

        yield [
            new Dsn('sendgrid', 'default', self::USER),
            new SendgridSmtpTransport(self::USER, null, $logger),
        ];

        
final class SendgridTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): TransportInterface
    {
        $scheme = $dsn->getScheme();
        $key = $this->getUser($dsn);

        if ('sendgrid+api' === $scheme) {
            $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
            $port = $dsn->getPort();

            return (new SendgridApiTransport($key$this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
        }

        if ('sendgrid+smtp' === $scheme || 'sendgrid+smtps' === $scheme || 'sendgrid' === $scheme) {
            return new SendgridSmtpTransport($key$this->dispatcher, $this->logger);
        }

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

    protected function getSupportedSchemes(): array
    {
        

    public function testToString(SendgridApiTransport $transport, string $expected)
    {
        $this->assertSame($expected(string) $transport);
    }

    public static function getTransportData()
    {
        return [
            [
                new SendgridApiTransport('KEY'),
                'sendgrid+api://api.sendgrid.com',
            ],
            [
                (new SendgridApiTransport('KEY'))->setHost('example.com'),
                'sendgrid+api://example.com',
            ],
            [
                (new SendgridApiTransport('KEY'))->setHost('example.com')->setPort(99),
                'sendgrid+api://example.com:99',
            ],
        ];
    }
Home | Imprint | This part of the site doesn't use cookies.