src/Subscriber/Caching/MessengerSubscriber.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Subscriber\Caching;
  3. use App\Event\Messenger\AttachmentBoughtEvent;
  4. use App\Event\Messenger\RouteReadEvent;
  5. use Frivol\Common\Service\CacheService;
  6. use App\Service\Client\Messenger\MessengerService;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class MessengerSubscriber implements EventSubscriberInterface
  9. {
  10.     protected MessengerService $service;
  11.     protected CacheService $cacheService;
  12.     public function __construct(CacheService $cacheServiceMessengerService $service)
  13.     {
  14.         $this->cacheService $cacheService;
  15.         $this->service $service;
  16.     }
  17.     public static function getSubscribedEvents()
  18.     {
  19.         return [
  20.             RouteReadEvent::class => [
  21.                 ['onRouteReadEvent'0]
  22.             ],
  23.             AttachmentBoughtEvent::class => [
  24.                 ['onAttachmentBoughtEvent'0]
  25.             ]
  26.         ];
  27.     }
  28.     /**
  29.      * @param AttachmentBoughtEvent $event
  30.      * @return void
  31.      * @throws \Psr\Cache\InvalidArgumentException
  32.      */
  33.     public function onAttachmentBoughtEvent(AttachmentBoughtEvent $event)
  34.     {
  35.         $this->cacheService->clearConversationCache($event->getConversation());
  36.     }
  37.     public function onRouteReadEvent(RouteReadEvent $event)
  38.     {
  39.         $this->service->markRouteAsRead($event->getConversation(), $event->getRoute());
  40.     }
  41. }