vendor/shopware/storefront/Theme/CachedResolvedConfigLoaderInvalidator.php line 36

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