-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFakeSmsTransportFactory.php
55 lines (45 loc) · 1.52 KB
/
FakeSmsTransportFactory.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace YieldStudio\Notifier\FakeSms;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Transport\TransportInterface;
/**
* @author James Hemery <[email protected]>
*/
final class FakeSmsTransportFactory extends AbstractTransportFactory
{
protected ?MailerInterface $mailer;
public function __construct(MailerInterface $mailer = null)
{
$this->mailer = $mailer;
parent::__construct();
}
/**
* @param Dsn $dsn
* @return FakeSmsTransport
*/
public function create(Dsn $dsn): TransportInterface
{
$scheme = $dsn->getScheme();
$to = $dsn->getOption('to');
$from = $dsn->getOption('from');
$host = $dsn->getHost();
if (!$to) {
throw new IncompleteDsnException('Missing to.', $dsn->getOriginalDsn());
}
if (!$from) {
throw new IncompleteDsnException('Missing from.', $dsn->getOriginalDsn());
}
if ('fakesms' === $scheme) {
return (new FakeSmsTransport($to, $from, $this->mailer))->setHost($host);
}
throw new UnsupportedSchemeException($dsn, 'fakesms', $this->getSupportedSchemes());
}
protected function getSupportedSchemes(): array
{
return ['fakesms'];
}
}