ScalewayApiTransport example


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

    public static function getTransportData()
    {
        return [
            [
                new ScalewayApiTransport('PROJECT_ID', 'TOKEN'),
                'scaleway+api://api.scaleway.com@PROJECT_ID',
            ],
            [
                new ScalewayApiTransport('PROJECT_ID', 'TOKEN', 'fr-par'),
                'scaleway+api://api.scaleway.com@PROJECT_ID?region=fr-par',
            ],
            [
                (new ScalewayApiTransport('PROJECT_ID', 'TOKEN'))->setHost('example.com'),
                'scaleway+api://example.com@PROJECT_ID',
            ],
            [
                (
new Dsn('scaleway+smtp', 'example.com'),
            true,
        ];
    }

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

        yield [
            new Dsn('scaleway+api', 'default', self::USER, self::PASSWORD, null, ['region' => 'fr-par']),
            new ScalewayApiTransport(self::USER, self::PASSWORD, 'fr-par', new MockHttpClient(), null, $logger),
        ];

        yield [
            new Dsn('scaleway', 'default', self::USER, self::PASSWORD),
            new ScalewayApiTransport(self::USER, self::PASSWORD, null, new MockHttpClient(), null, $logger),
        ];

        yield [
            new Dsn('scaleway+smtp', 'default', self::USER, self::PASSWORD),
            new ScalewaySmtpTransport(self::USER, self::PASSWORD, null, $logger),
        ];

        
public function create(Dsn $dsn): TransportInterface
    {
        $scheme = $dsn->getScheme();
        $projectId = $this->getUser($dsn);
        $token = $this->getPassword($dsn);

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

            return (new ScalewayApiTransport($projectId$token$region$this->client, $this->dispatcher, $this->logger))
                ->setHost($host)
                ->setPort($port);
        }

        if ('scaleway+smtp' === $scheme || 'scaleway+smtps' === $scheme) {
            return new ScalewaySmtpTransport($projectId$token$this->dispatcher, $this->logger);
        }

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

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