-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZenviaTransportFactory.php
37 lines (29 loc) · 1.08 KB
/
ZenviaTransportFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace Mangati\Notifier\Zenvia;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Transport\TransportInterface;
final class ZenviaTransportFactory extends AbstractTransportFactory
{
private const SCHEME = 'zenvia';
/**
* @return ZenviaTransport
*/
public function create(Dsn $dsn): TransportInterface
{
$scheme = $dsn->getScheme();
if (self::SCHEME !== $scheme) {
throw new UnsupportedSchemeException($dsn, self::SCHEME, $this->getSupportedSchemes());
}
$from = $this->getUser($dsn);
$token = $this->getPassword($dsn);
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();
return (new ZenviaTransport($from, $token, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
}
protected function getSupportedSchemes(): array
{
return [self::SCHEME];
}
}