<?php
namespace App\EventSubscriber\Customer;
use App\Events\Customer\SubscriptionEvent;
use App\Model\CustomerModel;
use App\Service\CustomerService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class Subscription implements EventSubscriberInterface
{
/** @var CustomerService */
protected $customerService;
/** @var CustomerModel */
protected $customerModel;
public function __construct(CustomerService $customerService, CustomerModel $customerModel)
{
$this->customerService = $customerService;
$this->customerModel = $customerModel;
}
public static function getSubscribedEvents(): array
{
return [
SubscriptionEvent::SUBSCRIBE_CUSTOMER => 'onSubscribeCustomer',
SubscriptionEvent::UNSUBSCRIBE_CUSTOMER => 'onUnsubscribeCustomer'
];
}
public function onSubscribeCustomer(SubscriptionEvent $event)
{
$customer = $event->getCustomer();
$this->customerService->subscribeCustomerFromRcaManualAlerts($customer);
$this->customerModel->subscribeCustomerToNewsletter($customer);
}
public function onUnsubscribeCustomer(SubscriptionEvent $event)
{
$customer = $event->getCustomer();
$this->customerService->unsubscribeCustomerFromAlerts($customer);
$this->customerService->unsubscribeCustomerFromRcaManualAlerts($customer);
$this->customerModel->unsubscribeCustomerFromNewsletter($customer);
}
}