src/Infrastructure/Event/Subscriber/EasyAdminSubscriber.php line 21

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Infrastructure\Event\Subscriber;
  4. use App\Domain\Common\Entity\IzOrderColor;
  5. use App\Infrastructure\Cache\ProductColorCacheManager;
  6. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. final class EasyAdminSubscriber implements EventSubscriberInterface
  9. {
  10.     private ProductColorCacheManager $colorCacheManager;
  11.     public function __construct(ProductColorCacheManager $colorCacheManager)
  12.     {
  13.         $this->colorCacheManager $colorCacheManager;
  14.     }
  15.     public function afterUpdate(AfterEntityUpdatedEvent $event): void
  16.     {
  17.         $entity $event->getEntityInstance();
  18.         if (!$entity instanceof IzOrderColor) {
  19.             return;
  20.         }
  21.         $this->colorCacheManager->delete($entity->getImportLabel());
  22.     }
  23.     public static function getSubscribedEvents(): array
  24.     {
  25.         return [
  26.             AfterEntityUpdatedEvent::class => 'afterUpdate',
  27.         ];
  28.     }
  29. }