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/sendinblue-notifier/SendinblueTransport.php line 34

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\Bridge\Sendinblue;
  11. use Symfony\Component\Notifier\Exception\TransportException;
  12. use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
  13. use Symfony\Component\Notifier\Message\MessageInterface;
  14. use Symfony\Component\Notifier\Message\SentMessage;
  15. use Symfony\Component\Notifier\Message\SmsMessage;
  16. use Symfony\Component\Notifier\Transport\AbstractTransport;
  17. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  18. use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  19. use Symfony\Contracts\HttpClient\HttpClientInterface;
  20. /**
  21.  * @author Pierre Tondereau <pierre.tondereau@gmail.com>
  22.  */
  23. final class SendinblueTransport extends AbstractTransport
  24. {
  25.     protected const HOST 'api.brevo.com';
  26.     private $apiKey;
  27.     private $sender;
  28.     public function __construct(string $apiKeystring $senderHttpClientInterface $client nullEventDispatcherInterface $dispatcher null)
  29.     {
  30.         $this->apiKey $apiKey;
  31.         $this->sender $sender;
  32.         parent::__construct($client$dispatcher);
  33.     }
  34.     public function __toString(): string
  35.     {
  36.         return sprintf('sendinblue://%s?sender=%s'$this->getEndpoint(), $this->sender);
  37.     }
  38.     public function supports(MessageInterface $message): bool
  39.     {
  40.         return $message instanceof SmsMessage;
  41.     }
  42.     protected function doSend(MessageInterface $message): SentMessage
  43.     {
  44.         if (!$message instanceof SmsMessage) {
  45.             throw new UnsupportedMessageTypeException(__CLASS__SmsMessage::class, $message);
  46.         }
  47.         $response $this->client->request('POST''https://'.$this->getEndpoint().'/v3/transactionalSMS/sms', [
  48.             'json' => [
  49.                 'sender' => $this->sender,
  50.                 'recipient' => $message->getPhone(),
  51.                 'content' => $message->getSubject(),
  52.             ],
  53.             'headers' => [
  54.                 'api-key' => $this->apiKey,
  55.             ],
  56.         ]);
  57.         try {
  58.             $statusCode $response->getStatusCode();
  59.         } catch (TransportExceptionInterface $e) {
  60.             throw new TransportException('Could not reach the remote Sendinblue server.'$response0$e);
  61.         }
  62.         if (201 !== $statusCode) {
  63.             $error $response->toArray(false);
  64.             throw new TransportException('Unable to send the SMS: '.($error['message'] ?? $response->getContent(false)), $response);
  65.         }
  66.         $success $response->toArray(false);
  67.         $sentMessage = new SentMessage($message, (string) $this);
  68.         $sentMessage->setMessageId($success['messageId']);
  69.         return $sentMessage;
  70.     }
  71. }