src/EventSubscriber/Customer/Subscription.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\Customer;
  3. use App\Events\Customer\SubscriptionEvent;
  4. use App\Model\CustomerModel;
  5. use App\Service\CustomerService;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class Subscription implements EventSubscriberInterface
  8. {
  9.     /** @var CustomerService */
  10.     protected $customerService;
  11.     /** @var CustomerModel */
  12.     protected $customerModel;
  13.     public function __construct(CustomerService $customerServiceCustomerModel $customerModel)
  14.     {
  15.         $this->customerService $customerService;
  16.         $this->customerModel $customerModel;
  17.     }
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             SubscriptionEvent::SUBSCRIBE_CUSTOMER => 'onSubscribeCustomer',
  22.             SubscriptionEvent::UNSUBSCRIBE_CUSTOMER => 'onUnsubscribeCustomer'
  23.         ];
  24.     }
  25.     public function onSubscribeCustomer(SubscriptionEvent $event)
  26.     {
  27.         $customer $event->getCustomer();
  28.         $this->customerService->subscribeCustomerFromRcaManualAlerts($customer);
  29.         $this->customerModel->subscribeCustomerToNewsletter($customer);
  30.     }
  31.     public function onUnsubscribeCustomer(SubscriptionEvent $event)
  32.     {
  33.         $customer $event->getCustomer();
  34.         $this->customerService->unsubscribeCustomerFromAlerts($customer);
  35.         $this->customerService->unsubscribeCustomerFromRcaManualAlerts($customer);
  36.         $this->customerModel->unsubscribeCustomerFromNewsletter($customer);
  37.     }
  38. }