AbstractTransportFactory.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. public function __construct(
  21. protected ?EventDispatcherInterface $dispatcher = null,
  22. protected ?HttpClientInterface $client = null,
  23. protected ?LoggerInterface $logger = null,
  24. ) {
  25. }
  26. public function supports(Dsn $dsn): bool
  27. {
  28. return \in_array($dsn->getScheme(), $this->getSupportedSchemes(), true);
  29. }
  30. abstract protected function getSupportedSchemes(): array;
  31. protected function getUser(Dsn $dsn): string
  32. {
  33. return $dsn->getUser() ?? throw new IncompleteDsnException('User is not set.');
  34. }
  35. protected function getPassword(Dsn $dsn): string
  36. {
  37. return $dsn->getPassword() ?? throw new IncompleteDsnException('Password is not set.');
  38. }
  39. }