src/Subscriber/Mail/DoiBounceSubscriber.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Subscriber\Mail;
  3. use App\Event\Mail\DoubleOptinCreatedEvent;
  4. use App\Service\Mail\DoubleOptinService;
  5. use App\Service\System\BounceService;
  6. use App\Service\System\MailProviderService;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class DoiBounceSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var MailProviderService
  12.      */
  13.     protected $doiService;
  14.     /**
  15.      * @var BounceService
  16.      */
  17.     protected $bounceService;
  18.     /**
  19.      * DoiBounceSubscriber constructor.
  20.      */
  21.     public function __construct(DoubleOptinService $doiServiceBounceService $bounceService)
  22.     {
  23.         $this->doiService $doiService;
  24.         $this->bounceService $bounceService;
  25.     }
  26.     public static function getSubscribedEvents(): array
  27.     {
  28.         return [
  29.             DoubleOptinCreatedEvent::class => [
  30.                 ['onDoiCreatedRemoveBounces'0],
  31.             ],
  32.         ];
  33.     }
  34.     /**
  35.      * @throws \Doctrine\DBAL\Exception
  36.      */
  37.     public function onDoiCreatedRemoveBounces(DoubleOptinCreatedEvent $event)
  38.     {
  39.         $account $event->getAccount();
  40.         $email $account->getEmail();
  41.         $domain $this->extractDomain($email);
  42.         $doiDomains $this->doiService->getDOIRequiredDomains();
  43.         if (in_array($domain$doiDomains)) {
  44.             $this->bounceService->deleteBouncesByAccountAndEmail($event->getAccount(), $email);
  45.         }
  46.     }
  47.     protected function extractDomain(string $email): string
  48.     {
  49.         return strtolower(substr($emailstrpos($email'@') + 1));
  50.     }
  51. }