-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractTransportFactory.php
78 lines (67 loc) · 2.07 KB
/
AbstractTransportFactory.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
* This file is part of the Klipper package.
*
* (c) François Pluchino <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Klipper\Component\SmsSender\Transport;
use Klipper\Component\SmsSender\Exception\IncompleteDsnException;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* Abstract class for the transport.
*
* @author François Pluchino <[email protected]>
*/
abstract class AbstractTransportFactory implements TransportFactoryInterface
{
protected ?EventDispatcherInterface $dispatcher;
protected ?HttpClientInterface $client;
protected ?LoggerInterface $logger;
/**
* @param null|EventDispatcherInterface $dispatcher The event dispatcher
* @param null|HttpClientInterface $client The http client
* @param null|LoggerInterface $logger The logger
*/
public function __construct(
?EventDispatcherInterface $dispatcher = null,
?HttpClientInterface $client = null,
?LoggerInterface $logger = null
) {
$this->dispatcher = $dispatcher;
$this->client = $client;
$this->logger = $logger;
}
/**
* Get the user.
*
* @param Dsn $dsn The dsn instance
*
* @throws IncompleteDsnException When user is not set
*/
protected function getUser(Dsn $dsn): string
{
if (null === $user = $dsn->getUser()) {
throw new IncompleteDsnException('User is not set');
}
return $user;
}
/**
* Get the password.
*
* @param Dsn $dsn The dsn instance
*
* @throws IncompleteDsnException When password is not set
*/
protected function getPassword(Dsn $dsn): string
{
if (null === $password = $dsn->getPassword()) {
throw new IncompleteDsnException('Password is not set');
}
return $password;
}
}