src/Subscriber/User/FriendshipSubscriber.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Subscriber\User;
  3. use App\Event\User\FriendshipConfirmedEvent;
  4. use App\Event\User\FriendshipDeletedEvent;
  5. use App\Event\User\FriendshipEvent;
  6. use App\Event\User\FriendshipRequestedEvent;
  7. use App\Service\Client\Messenger\MessengerService;
  8. use App\Service\Client\User\FriendshipService;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. class FriendshipSubscriber implements EventSubscriberInterface
  11. {
  12.     protected FriendshipService $service;
  13.     public function __construct(FriendshipService $serviceMessengerService $messengerService)
  14.     {
  15.         $this->service $service;
  16.     }
  17.     /**
  18.      * @return array
  19.      */
  20.     public static function getSubscribedEvents()
  21.     {
  22.         return [
  23.             FriendshipRequestedEvent::class => [
  24.                 ['onFriendshipEventClearCachesForBoth'0],
  25.             ],
  26.             FriendshipDeletedEvent::class => [
  27.                 ['onFriendshipEventClearCachesForBoth'0],
  28.             ],
  29.             FriendshipConfirmedEvent::class => [
  30.                 ['onFriendshipEventClearCachesForBoth'0],
  31.             ]
  32.         ];
  33.     }
  34.     /**
  35.      * @param FriendshipEvent $event
  36.      * @throws \Psr\Cache\InvalidArgumentException
  37.      */
  38.     public function onFriendshipEventClearCachesForBoth(FriendshipEvent $event)
  39.     {
  40.         $this->service->clearMemberFriendshipCache([
  41.             $event->getIssuer(),
  42.             $event->getTarget()
  43.         ]);
  44.     }
  45. }