vendor/nellapp/sdk-bundle/src/Channel/EventSubscriber/ChannelMenuDisplayedSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. namespace Nellapp\Bundle\SDKBundle\Channel\EventSubscriber;
  3. use Nellapp\Bundle\SDKBundle\Permission\Event\ChannelMenuDisplayedEvent;
  4. use Nellapp\Bundle\SDKBundle\Sync\ApiClient\ChannelUserData\ChannelUserDataEntityClient;
  5. use Psr\Log\LoggerInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
  8. use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
  9. use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
  10. use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
  11. use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
  12. use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  13. class ChannelMenuDisplayedSubscriber implements EventSubscriberInterface
  14. {
  15. public function __construct(
  16. private ChannelUserDataEntityClient $channelUserDataClient,
  17. private LoggerInterface $logger,
  18. )
  19. {
  20. }
  21. public static function getSubscribedEvents(): array
  22. {
  23. return [
  24. ChannelMenuDisplayedEvent::class => '__invoke',
  25. ];
  26. }
  27. public function __invoke(ChannelMenuDisplayedEvent $event): void
  28. {
  29. try {
  30. $this->channelUserDataClient->patchMenuDisplayed($event->getChannelUserDataId(), $event->getNoAccessLinks(), $event->getAccessLinks());
  31. } catch (ClientExceptionInterface|RedirectionExceptionInterface|ServerExceptionInterface|TransportExceptionInterface|ServiceUnavailableHttpException|UnauthorizedHttpException $e) {
  32. $this->logger->error($e);
  33. }
  34. }
  35. }