1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Mailer\Transport;
13
14use Psr\Log\LoggerInterface;
15use Symfony\Component\Mailer\Exception\IncompleteDsnException;
16use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
17use Symfony\Contracts\HttpClient\HttpClientInterface;
18
19/**
20 * @author Konstantin Myakshin <molodchick@gmail.com>
21 */
22abstract class AbstractTransportFactory implements TransportFactoryInterface
23{
24    protected $dispatcher;
25    protected $client;
26    protected $logger;
27
28    public function __construct(EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null, LoggerInterface $logger = null)
29    {
30        $this->dispatcher = $dispatcher;
31        $this->client = $client;
32        $this->logger = $logger;
33    }
34
35    public function supports(Dsn $dsn): bool
36    {
37        return \in_array($dsn->getScheme(), $this->getSupportedSchemes());
38    }
39
40    abstract protected function getSupportedSchemes(): array;
41
42    protected function getUser(Dsn $dsn): string
43    {
44        $user = $dsn->getUser();
45        if (null === $user) {
46            throw new IncompleteDsnException('User is not set.');
47        }
48
49        return $user;
50    }
51
52    protected function getPassword(Dsn $dsn): string
53    {
54        $password = $dsn->getPassword();
55        if (null === $password) {
56            throw new IncompleteDsnException('Password is not set.');
57        }
58
59        return $password;
60    }
61}
62