src/Event/Form/UniSenderSubscriber.php line 22

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Antony Tkachenko <at@canaryknight.ru>
  4.  */
  5. namespace App\Event\Form;
  6. use App\Form\Contracts\UniSender;
  7. use App\Form\FormHandledEvent;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class UniSenderSubscriber implements EventSubscriberInterface
  10. {
  11.     /** @var string|null */
  12.     private $token;
  13.     public function __construct(?string $token)
  14.     {
  15.         $this->token $token;
  16.     }
  17.     public function subscribe(FormHandledEvent $event)
  18.     {
  19.         if (!$this->token) {
  20.             return;
  21.         }
  22.         $dto $event->getDto();
  23.         if (!is_a($dtoUniSender::class)) {
  24.             return;
  25.         }
  26.         try {
  27.             $data = [
  28.                 'format' => 'json',
  29.                 'api_key' => $this->token,
  30.                 'list_ids' => 4,
  31.                 'fields' => [
  32.                     'email' => $dto->getEmail()
  33.                 ],
  34.                 'double_optin' => 3,
  35.             ];
  36.             $testUrl 'https://api.unisender.com/ru/api/subscribe?' http_build_query($data);
  37.             $res file_get_contents($testUrl);
  38.         } catch (\Exception $e) {}
  39.     }
  40.     public static function getSubscribedEvents()
  41.     {
  42.         return [
  43.             FormHandledEvent::NAME => 'subscribe'
  44.         ];
  45.     }
  46. }