<?php
namespace Nellapp\Bundle\SDKBundle\Channel\EventSubscriber;
use Nellapp\Bundle\SDKBundle\Permission\Event\ChannelMenuDisplayedEvent;
use Nellapp\Bundle\SDKBundle\Sync\ApiClient\ChannelUserData\ChannelUserDataClient;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
class ChannelMenuDisplayedSubscriber implements EventSubscriberInterface
{
public function __construct(
private ChannelUserDataClient $channelUserDataClient,
private LoggerInterface $logger,
)
{
}
public static function getSubscribedEvents(): array
{
return [
ChannelMenuDisplayedEvent::class => '__invoke',
];
}
public function __invoke(ChannelMenuDisplayedEvent $event): void
{
try {
$this->channelUserDataClient->patchMenuDisplayed($event->getChannelUserDataId(), $event->getNoAccessLinks(), $event->getAccessLinks());
} catch (ClientExceptionInterface|RedirectionExceptionInterface|ServerExceptionInterface|TransportExceptionInterface $e) {
$this->logger->error($e);
}
}
}