Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

vendor/symfony/notifier/Transport/AbstractTransport.php line 39

Open in your IDE?
  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\Notifier\Transport;
  11. use Symfony\Component\EventDispatcher\Event;
  12. use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
  13. use Symfony\Component\HttpClient\HttpClient;
  14. use Symfony\Component\Notifier\Event\FailedMessageEvent;
  15. use Symfony\Component\Notifier\Event\MessageEvent;
  16. use Symfony\Component\Notifier\Event\SentMessageEvent;
  17. use Symfony\Component\Notifier\Exception\LogicException;
  18. use Symfony\Component\Notifier\Message\MessageInterface;
  19. use Symfony\Component\Notifier\Message\SentMessage;
  20. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  21. use Symfony\Contracts\HttpClient\HttpClientInterface;
  22. /**
  23.  * @author Fabien Potencier <fabien@symfony.com>
  24.  */
  25. abstract class AbstractTransport implements TransportInterface
  26. {
  27.     protected const HOST 'localhost';
  28.     private $dispatcher;
  29.     protected $client;
  30.     protected $host;
  31.     protected $port;
  32.     public function __construct(HttpClientInterface $client nullEventDispatcherInterface $dispatcher null)
  33.     {
  34.         $this->client $client;
  35.         if (null === $client) {
  36.             if (!class_exists(HttpClient::class)) {
  37.                 throw new LogicException(sprintf('You cannot use "%s" as the HttpClient component is not installed. Try running "composer require symfony/http-client".'__CLASS__));
  38.             }
  39.             $this->client HttpClient::create();
  40.         }
  41.         $this->dispatcher class_exists(Event::class) ? LegacyEventDispatcherProxy::decorate($dispatcher) : $dispatcher;
  42.     }
  43.     /**
  44.      * @return $this
  45.      */
  46.     public function setHost(?string $host): self
  47.     {
  48.         $this->host $host;
  49.         return $this;
  50.     }
  51.     /**
  52.      * @return $this
  53.      */
  54.     public function setPort(?int $port): self
  55.     {
  56.         $this->port $port;
  57.         return $this;
  58.     }
  59.     public function send(MessageInterface $message): SentMessage
  60.     {
  61.         if (null === $this->dispatcher) {
  62.             return $this->doSend($message);
  63.         }
  64.         $this->dispatcher->dispatch(new MessageEvent($message));
  65.         try {
  66.             $sentMessage $this->doSend($message);
  67.         } catch (\Throwable $error) {
  68.             $this->dispatcher->dispatch(new FailedMessageEvent($message$error));
  69.             throw $error;
  70.         }
  71.         $this->dispatcher->dispatch(new SentMessageEvent($sentMessage));
  72.         return $sentMessage;
  73.     }
  74.     abstract protected function doSend(MessageInterface $message): SentMessage;
  75.     protected function getEndpoint(): string
  76.     {
  77.         return ($this->host ?: $this->getDefaultHost()).($this->port ':'.$this->port '');
  78.     }
  79.     protected function getDefaultHost(): string
  80.     {
  81.         return static::HOST;
  82.     }
  83. }