src/V4/EventSubscriber/MicrosoftGraph/RemoveOutlookSubscriptionUserEventSubscriber.php line 63

Open in your IDE?
  1. <?php
  2. namespace App\V4\EventSubscriber\MicrosoftGraph;
  3. use ApiPlatform\Core\Exception\ResourceClassNotSupportedException;
  4. use App\Service\Cache\Exception\UnableToSaveKeyException;
  5. use App\V4\Event\OutlookSubscriptionConfigurationUserRemoveEvent;
  6. use App\V4\EventSubscriber\AbstractSubscriber;
  7. use App\V4\Manager\MicrosoftGraph\OutlookSubscriptionManager;
  8. use App\V4\Model\OutlookSubscriptionConfigurationUser\OutlookSubscriptionConfigurationUser;
  9. use Psr\Cache\CacheException;
  10. use Psr\Cache\InvalidArgumentException;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
  13. use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
  14. use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
  15. use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  16. class RemoveOutlookSubscriptionUserEventSubscriber extends AbstractSubscriber implements EventSubscriberInterface
  17. {
  18.     /**
  19.      * @var OutlookSubscriptionManager
  20.      */
  21.     private $outlookSubscriptionManager;
  22.     public function __construct(OutlookSubscriptionManager $outlookSubscriptionManager)
  23.     {
  24.         $this->outlookSubscriptionManager $outlookSubscriptionManager;
  25.     }
  26.     /**
  27.      * @param $entity
  28.      *
  29.      * @return bool
  30.      */
  31.     public function supports($entity): bool
  32.     {
  33.         return $entity instanceof OutlookSubscriptionConfigurationUser;
  34.     }
  35.     /**
  36.      * @return string[]
  37.      */
  38.     public static function getSubscribedEvents(): array
  39.     {
  40.         return [
  41.             OutlookSubscriptionConfigurationUserRemoveEvent::NAME => 'onOutlookSubConfUserRemove',
  42.         ];
  43.     }
  44.     /**
  45.      * @param OutlookSubscriptionConfigurationUserRemoveEvent $event
  46.      *
  47.      * @throws ResourceClassNotSupportedException
  48.      * @throws UnableToSaveKeyException
  49.      * @throws CacheException
  50.      * @throws InvalidArgumentException
  51.      * @throws ClientExceptionInterface
  52.      * @throws RedirectionExceptionInterface
  53.      * @throws ServerExceptionInterface
  54.      * @throws TransportExceptionInterface
  55.      */
  56.     public function onOutlookSubConfUserRemove(OutlookSubscriptionConfigurationUserRemoveEvent $event): void
  57.     {
  58.         if ($this->supports($event->getOutlookSubscriptionConfigurationUser())
  59.             && !$this->isIdAlreadyManaged($event->getOutlookSubscriptionConfigurationUser()->getId(), get_class($this))) {
  60.             $this->outlookSubscriptionManager->unsubscribe($event->getOutlookSubscriptionConfigurationUser());
  61.         }
  62.     }
  63. }