setPort example


        $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
    {
        return ['firebase'];
    }
}
$scheme = $dsn->getScheme();

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

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

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

    protected function getSupportedSchemes(): array
    {
        return ['clickatell'];
    }
}
if ('orange-sms' !== $scheme) {
            throw new UnsupportedSchemeException($dsn, 'orange-sms', $this->getSupportedSchemes());
        }

        $user = $this->getUser($dsn);
        $password = $this->getPassword($dsn);
        $from = $dsn->getRequiredOption('from');
        $senderName = $dsn->getOption('sender_name');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new OrangeSmsTransport($user$password$from$senderName$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        return ['orange-sms'];
    }
}
/** * @group time-sensitive */
class SmtpTransportTest extends TestCase
{
    public function testToString()
    {
        $t = new SmtpTransport();
        $this->assertEquals('smtps://localhost', (string) $t);

        $t = new SmtpTransport((new SocketStream())->setHost('127.0.0.1')->setPort(2525)->disableTls());
        $this->assertEquals('smtp://127.0.0.1:2525', (string) $t);
    }

    public function testSendDoesNotPingBelowThreshold()
    {
        $stream = new DummyStream();
        $envelope = new Envelope(new Address('sender@example.org')[new Address('recipient@example.org')]);

        $transport = new SmtpTransport($stream);
        $transport->send(new RawMessage('Message 1')$envelope);
        $transport->send(new RawMessage('Message 2')$envelope);
        

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

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

        return (new ChatworkTransport($token$roomId$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }
}
if ('vonage' !== $scheme) {
            throw new UnsupportedSchemeException($dsn, 'vonage', $this->getSupportedSchemes());
        }

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

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

    protected function getSupportedSchemes(): array
    {
        return ['vonage'];
    }
}
$transport = $this->createTransport();

        $transport->setHost($customHost = self::CUSTOM_HOST);

        $this->assertMatchesRegularExpression(sprintf('/^.*\:\/\/(%s|.*\@%s)/', $customHost$customHost)(string) $transport);
    }

    public function testCanSetCustomPort()
    {
        $transport = $this->createTransport();

        $transport->setPort($customPort = self::CUSTOM_PORT);

        /* * @see https://regex101.com/r/shT9O2/1 */
        $this->assertMatchesRegularExpression(sprintf('/^.*\:\/\/.*(\@.*)?\:%s((\?.*|\/.*))?$/', $customPort)(string) $transport);
    }

    public function testCanSetCustomHostAndPort()
    {
        $transport = $this->createTransport();

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

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

        return [
            [
                new MailPaceApiTransport('KEY'),
                'mailpace+api://app.mailpace.com/api/v1',
            ],
            [
                (new MailPaceApiTransport('KEY'))->setHost('example.com'),
                'mailpace+api://example.com',
            ],
            [
                (new MailPaceApiTransport('KEY'))->setHost('example.com')->setPort(99),
                'mailpace+api://example.com:99',
            ],
        ];
    }

    public function testCustomHeader()
    {
        $email = new Email();
        $email->getHeaders()->addTextHeader('foo', 'bar');
        $envelope = new Envelope(new Address('alice@system.com')[new Address('bob@system.com')]);

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

        $userLogin = urlencode($this->getUser($dsn));
        $apiKey = $this->getPassword($dsn);
        $from = $dsn->getRequiredOption('from');
        $type = $dsn->getRequiredOption('type');

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

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

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

        }

        if ($dsn->getOption('region')) {
            $options['region'] = $dsn->getOption('region');
        }

        if ($dsn->getOption('profile')) {
            $options['profile'] = $dsn->getOption('profile');
        }

        return (new AmazonSnsTransport(new SnsClient($options, null, $this->client)$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

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

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

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

            return (new MailPaceApiTransport($this->getUser($dsn)$this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
        }

        if ('mailpace+smtp' === $scheme || 'mailpace+smtps' === $scheme || 'mailpace' === $scheme) {
            return new MailPaceSmtpTransport($this->getUser($dsn)$this->dispatcher, $this->logger);
        }

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

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

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

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

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

        yield [
            new Dsn('mailpace+smtp', 'default', self::USER),
            new MailPaceSmtpTransport(self::USER, null, $logger),
        ];

        

        return [
            [
                new OhMySmtpApiTransport('KEY'),
                'ohmysmtp+api://app.ohmysmtp.com/api/v1',
            ],
            [
                (new OhMySmtpApiTransport('KEY'))->setHost('example.com'),
                'ohmysmtp+api://example.com',
            ],
            [
                (new OhMySmtpApiTransport('KEY'))->setHost('example.com')->setPort(99),
                'ohmysmtp+api://example.com:99',
            ],
        ];
    }

    public function testCustomHeader()
    {
        $email = new Email();
        $email->getHeaders()->addTextHeader('foo', 'bar');
        $envelope = new Envelope(new Address('alice@system.com')[new Address('bob@system.com')]);

        

        $scheme = $dsn->getScheme();

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

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

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

    protected function getSupportedSchemes(): array
    {
        return ['mastodon'];
    }
}
Home | Imprint | This part of the site doesn't use cookies.