vendor/shopware/platform/src/Storefront/Theme/CachedResolvedConfigLoaderInvalidator.php line 51

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.     /**
  17.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  18.      */
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return [
  22.             ThemeConfigChangedEvent::class => 'invalidate',
  23.             ThemeAssignedEvent::class => 'assigned',
  24.             ThemeConfigResetEvent::class => 'reset',
  25.         ];
  26.     }
  27.     public function invalidate(ThemeConfigChangedEvent $event): void
  28.     {
  29.         $tags = [CachedResolvedConfigLoader::buildName($event->getThemeId())];
  30.         $keys array_keys($event->getConfig());
  31.         foreach ($keys as $key) {
  32.             $tags[] = ThemeConfigValueAccessor::buildName($key);
  33.         }
  34.         $this->logger->invalidate($tags);
  35.     }
  36.     public function assigned(ThemeAssignedEvent $event): void
  37.     {
  38.         $this->logger->invalidate([CachedResolvedConfigLoader::buildName($event->getThemeId())]);
  39.         $this->logger->invalidate([CachedDomainLoader::CACHE_KEY]);
  40.     }
  41.     public function reset(ThemeConfigResetEvent $event): void
  42.     {
  43.         $this->logger->invalidate([CachedResolvedConfigLoader::buildName($event->getThemeId())]);
  44.     }
  45. }