platform/src/Storefront/Theme/CachedResolvedConfigLoaderInvalidator.php line 30

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Theme;
  3. use Shopware\Core\Framework\Adapter\Cache\CacheInvalidator;
  4. use Shopware\Storefront\Framework\Routing\CachedDomainLoader;
  5. use Shopware\Storefront\Theme\Event\ThemeAssignedEvent;
  6. use Shopware\Storefront\Theme\Event\ThemeConfigChangedEvent;
  7. use Shopware\Storefront\Theme\Event\ThemeConfigResetEvent;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class CachedResolvedConfigLoaderInvalidator implements EventSubscriberInterface
  10. {
  11.     private CacheInvalidator $logger;
  12.     public function __construct(CacheInvalidator $logger)
  13.     {
  14.         $this->logger $logger;
  15.     }
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return [
  19.             ThemeConfigChangedEvent::class => 'invalidate',
  20.             ThemeAssignedEvent::class => 'assigned',
  21.             ThemeConfigResetEvent::class => 'reset',
  22.         ];
  23.     }
  24.     public function invalidate(ThemeConfigChangedEvent $event): void
  25.     {
  26.         $tags = [CachedResolvedConfigLoader::buildName($event->getThemeId())];
  27.         $keys array_keys($event->getConfig());
  28.         foreach ($keys as $key) {
  29.             $tags[] = ThemeConfigValueAccessor::buildName($key);
  30.         }
  31.         $this->logger->invalidate($tags);
  32.     }
  33.     public function assigned(ThemeAssignedEvent $event): void
  34.     {
  35.         $this->logger->invalidate([CachedResolvedConfigLoader::buildName($event->getThemeId())]);
  36.         $this->logger->invalidate([CachedDomainLoader::CACHE_KEY]);
  37.     }
  38.     public function reset(ThemeConfigResetEvent $event): void
  39.     {
  40.         $this->logger->invalidate([CachedResolvedConfigLoader::buildName($event->getThemeId())]);
  41.     }
  42. }