src/EventSubscriber/BackgroundSubscriber.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Handler\ContainerHandler;
  4. use App\Event\BackgroundPostUpdateEvent;
  5. use App\Event\BackgroundPostRemoveEvent;
  6. use App\Event\BackgroundPostPersistEvent;
  7. use Symfony\Contracts\Cache\TagAwareCacheInterface;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class BackgroundSubscriber implements EventSubscriberInterface
  10. {
  11.     public function __construct(
  12.         private TagAwareCacheInterface $esComCache
  13.     ) {}
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             BackgroundPostPersistEvent::NAME => 'onCreate',
  18.             BackgroundPostUpdateEvent::NAME => 'onUpdate',
  19.             BackgroundPostRemoveEvent::NAME => 'onDelete'
  20.         ];
  21.     }
  22.     public function onCreate(BackgroundPostPersistEvent $event)
  23.     {
  24.         $this->removeContainerFromCache($event);
  25.     }
  26.     public function onUpdate(BackgroundPostUpdateEvent $event)
  27.     {
  28.         $this->removeContainerFromCache($event);
  29.     }
  30.     public function onDelete(BackgroundPostRemoveEvent $event)
  31.     {
  32.         $this->removeContainerFromCache($event);
  33.     }
  34.     private function removeContainerFromCache($event)
  35.     {
  36.         $object $event->getObject();
  37.         $containerId $object->getContainer()->getId();
  38.         //$this->esComCache->invalidateTags(['ES_CONTAINER_'.$containerId, 'ES_MY_CONTAINER_'.$containerId]);
  39.         $this->esComCache->invalidateTags(['ES_CONTAINER''ES_MY_CONTAINER']);
  40.     }
  41. }