MailerSendApiTransport example

/** * @dataProvider getTransportData */
    public function testToString(MailerSendApiTransport $transport, string $expected)
    {
        $this->assertSame($expected(string) $transport);
    }

    public static function getTransportData()
    {
        yield [
            new MailerSendApiTransport('ACCESS_KEY'),
            'mailersend+api://api.mailersend.com',
        ];

        yield [
            (new MailerSendApiTransport('ACCESS_KEY'))->setHost('example.com'),
            'mailersend+api://example.com',
        ];

        yield [
            (new MailerSendApiTransport('ACCESS_KEY'))->setHost('example.com')->setPort(99),
            'mailersend+api://example.com:99',
        ];
use Symfony\Component\Mailer\Transport\Dsn;
use Symfony\Component\Mailer\Transport\TransportInterface;

/** * @author Yann LUCAS */
final class MailerSendTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): TransportInterface
    {
        return match ($dsn->getScheme()) {
            'mailersend+api' => (new MailerSendApiTransport($this->getUser($dsn)$this->client, $this->dispatcher, $this->logger))
                ->setHost('default' === $dsn->getHost() ? null : $dsn->getHost())
                ->setPort($dsn->getPort()),

            'mailersend', 'mailersend+smtp' => new MailerSendSmtpTransport($this->getUser($dsn)$this->getPassword($dsn)$this->dispatcher, $this->logger),

            default => throw new UnsupportedSchemeException($dsn, 'mailersend', $this->getSupportedSchemes())
        };
    }

    protected function getSupportedSchemes(): array
    {
        
new Dsn('mailersend+smtp', 'default', self::USER, self::PASSWORD),
            new MailerSendSmtpTransport(self::USER, self::PASSWORD, null, new NullLogger()),
        ];

        yield [
            new Dsn('mailersend+smtp', 'default', self::USER, self::PASSWORD, 465),
            new MailerSendSmtpTransport(self::USER, self::PASSWORD, null, new NullLogger()),
        ];

        yield [
            new Dsn('mailersend+api', 'default', self::USER),
            new MailerSendApiTransport(self::USER, new MockHttpClient(), null, new NullLogger()),
        ];
    }

    public static function unsupportedSchemeProvider(): iterable
    {
        yield [
            new Dsn('mailersend+foo', 'default', self::USER, self::PASSWORD),
            'The "mailersend+foo" scheme is not supported; supported schemes for mailer "mailersend" are: "mailersend", "mailersend+smtp", "mailersend+api".',
        ];
    }

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