src/EventSubscriber/Klaviyo/KlaviyoEmailEntered.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\Klaviyo;
  3. use Exception;
  4. use App\Event\EmailEntered;
  5. use App\Service\Klaviyo\KlaviyoEmail;
  6. use App\Service\Klaviyo\KlaviyoProfileService;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class KlaviyoEmailEntered implements EventSubscriberInterface
  9. {
  10.     public function __construct(
  11.         private KlaviyoProfileService $klaviyoProfileService,
  12.         private KlaviyoEmail $klaviyoEmail
  13.     )
  14.     {
  15.         
  16.     }
  17.     public function onEmailEntered(EmailEntered $event): void
  18.     {
  19.         try {
  20.             $this->klaviyoEmail->setEmail($event->getEmail());
  21.             $this->klaviyoProfileService->identify($event->getEmail());
  22.         } catch (Exception $e) {
  23.         }
  24.     }
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [
  28.             EmailEntered::NAME => 'onEmailEntered',
  29.         ];
  30.     }
  31. }