<?php declare(strict_types=1);
namespace Acris\ShopSwitch\Subscriber;
use Shopware\Core\Framework\Adapter\Cache\CacheInvalidator;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ShopSwitchCacheSubscriber implements EventSubscriberInterface
{
const SWITCH_RULE_WRITTEN_EVENT = 'acris_switch_rule.written';
const HEADER_CACHE_TAG = 'acris-shop-switch';
const MODAL_DATA_CACHE_TAG = 'acris-shop-switch-modal-data';
private CacheInvalidator $logger;
public function __construct(CacheInvalidator $logger)
{
$this->logger = $logger;
}
public static function getSubscribedEvents()
{
return [
self::SWITCH_RULE_WRITTEN_EVENT => 'onSwitchRuleWrittenEvent'
];
}
public function onSwitchRuleWrittenEvent (EntityWrittenEvent $event): void
{
$this->logger->invalidate(
[self::HEADER_CACHE_TAG, self::MODAL_DATA_CACHE_TAG]
);
}
}