src/V4/EventSubscriber/MicrosoftGraph/CreateOutlookSubscriptionEventSubscriber.php line 61

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