vendor/symfony/mailer/Transport/Smtp/EsmtpTransportFactory.php line 30

  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\Smtp;
  11. use Symfony\Component\Mailer\Transport\AbstractTransportFactory;
  12. use Symfony\Component\Mailer\Transport\Dsn;
  13. use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
  14. use Symfony\Component\Mailer\Transport\TransportInterface;
  15. /**
  16.  * @author Konstantin Myakshin <molodchick@gmail.com>
  17.  */
  18. final class EsmtpTransportFactory extends AbstractTransportFactory
  19. {
  20.     public function create(Dsn $dsn): TransportInterface
  21.     {
  22.         $tls 'smtps' === $dsn->getScheme() ? true null;
  23.         $port $dsn->getPort(0);
  24.         $host $dsn->getHost();
  25.         $transport = new EsmtpTransport($host$port$tls$this->dispatcher$this->logger);
  26.         if ('' !== $dsn->getOption('verify_peer') && !filter_var($dsn->getOption('verify_peer'true), \FILTER_VALIDATE_BOOL)) {
  27.             /** @var SocketStream $stream */
  28.             $stream $transport->getStream();
  29.             $streamOptions $stream->getStreamOptions();
  30.             $streamOptions['ssl']['verify_peer'] = false;
  31.             $streamOptions['ssl']['verify_peer_name'] = false;
  32.             $stream->setStreamOptions($streamOptions);
  33.         }
  34.         if ($user $dsn->getUser()) {
  35.             $transport->setUsername($user);
  36.         }
  37.         if ($password $dsn->getPassword()) {
  38.             $transport->setPassword($password);
  39.         }
  40.         if (null !== ($localDomain $dsn->getOption('local_domain'))) {
  41.             $transport->setLocalDomain($localDomain);
  42.         }
  43.         if (null !== ($maxPerSecond $dsn->getOption('max_per_second'))) {
  44.             $transport->setMaxPerSecond((float) $maxPerSecond);
  45.         }
  46.         if (null !== ($restartThreshold $dsn->getOption('restart_threshold'))) {
  47.             $transport->setRestartThreshold((int) $restartThreshold, (int) $dsn->getOption('restart_threshold_sleep'0));
  48.         }
  49.         if (null !== ($pingThreshold $dsn->getOption('ping_threshold'))) {
  50.             $transport->setPingThreshold((int) $pingThreshold);
  51.         }
  52.         return $transport;
  53.     }
  54.     protected function getSupportedSchemes(): array
  55.     {
  56.         return ['smtp''smtps'];
  57.     }
  58. }