<?php
declare(strict_types=1);
namespace App\Infrastructure\Event\Subscriber;
use App\Domain\Common\Entity\IzOrderColor;
use App\Infrastructure\Cache\ProductColorCacheManager;
use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
final class EasyAdminSubscriber implements EventSubscriberInterface
{
private ProductColorCacheManager $colorCacheManager;
public function __construct(ProductColorCacheManager $colorCacheManager)
{
$this->colorCacheManager = $colorCacheManager;
}
public function afterUpdate(AfterEntityUpdatedEvent $event): void
{
$entity = $event->getEntityInstance();
if (!$entity instanceof IzOrderColor) {
return;
}
$this->colorCacheManager->delete($entity->getImportLabel());
}
public static function getSubscribedEvents(): array
{
return [
AfterEntityUpdatedEvent::class => 'afterUpdate',
];
}
}