AbstractTransportFactory.php 1.5 KB

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