<?php
namespace App\Subscriber\User;
use App\Event\User\FriendshipConfirmedEvent;
use App\Event\User\FriendshipDeletedEvent;
use App\Event\User\FriendshipEvent;
use App\Event\User\FriendshipRequestedEvent;
use App\Service\Client\Messenger\MessengerService;
use App\Service\Client\User\FriendshipService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class FriendshipSubscriber implements EventSubscriberInterface
{
protected FriendshipService $service;
public function __construct(FriendshipService $service, MessengerService $messengerService)
{
$this->service = $service;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
FriendshipRequestedEvent::class => [
['onFriendshipEventClearCachesForBoth', 0],
],
FriendshipDeletedEvent::class => [
['onFriendshipEventClearCachesForBoth', 0],
],
FriendshipConfirmedEvent::class => [
['onFriendshipEventClearCachesForBoth', 0],
]
];
}
/**
* @param FriendshipEvent $event
* @throws \Psr\Cache\InvalidArgumentException
*/
public function onFriendshipEventClearCachesForBoth(FriendshipEvent $event)
{
$this->service->clearMemberFriendshipCache([
$event->getIssuer(),
$event->getTarget()
]);
}
}