<?php
namespace App\EventSubscriber\Klaviyo;
use Exception;
use App\Event\EmailEntered;
use App\Service\Klaviyo\KlaviyoEmail;
use App\Service\Klaviyo\KlaviyoProfileService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class KlaviyoEmailEntered implements EventSubscriberInterface
{
public function __construct(
private KlaviyoProfileService $klaviyoProfileService,
private KlaviyoEmail $klaviyoEmail
)
{
}
public function onEmailEntered(EmailEntered $event): void
{
try {
$this->klaviyoEmail->setEmail($event->getEmail());
$this->klaviyoProfileService->identify($event->getEmail());
} catch (Exception $e) {
}
}
public static function getSubscribedEvents(): array
{
return [
EmailEntered::NAME => 'onEmailEntered',
];
}
}