<?php
namespace Neno\MarketingEssentials\Subscriber;
use Shopware\Core\Framework\Adapter\Cache\CacheClearer;
use Shopware\Core\System\SystemConfig\Event\SystemConfigChangedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class SystemConfigChangedSubscriber implements EventSubscriberInterface {
private CacheClearer $cacheClearer;
public function __construct
(
CacheClearer $cacheClearer
) {
$this->cacheClearer = $cacheClearer;
}
static string $PLUGIN_NAME = 'NenoMarketingEssentials';
public static function getSubscribedEvents(): array
{
return [
SystemConfigChangedEvent::class => 'onConfigChanged'
];
}
private function shouldHandle(string $key): bool {
return (strpos($key, self::$PLUGIN_NAME . '.config') === 0);
}
public function onConfigChanged(SystemConfigChangedEvent $event):void {
if ($this->shouldHandle($event->getKey())) {
$this->cacheClearer->clear();
}
}
}