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

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\Theme\Event\ThemeAssignedEvent;
  5. use Shopware\Storefront\Theme\Event\ThemeConfigChangedEvent;
  6. use Shopware\Storefront\Theme\Event\ThemeConfigResetEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class CachedResolvedConfigLoaderInvalidator implements EventSubscriberInterface
  9. {
  10.     private CacheInvalidator $logger;
  11.     public function __construct(CacheInvalidator $logger)
  12.     {
  13.         $this->logger $logger;
  14.     }
  15.     public static function getSubscribedEvents()
  16.     {
  17.         return [
  18.             ThemeConfigChangedEvent::class => 'invalidate',
  19.             ThemeAssignedEvent::class => 'assigned',
  20.             ThemeConfigResetEvent::class => 'reset',
  21.         ];
  22.     }
  23.     public function invalidate(ThemeConfigChangedEvent $event): void
  24.     {
  25.         $tags = [CachedResolvedConfigLoader::buildName($event->getThemeId())];
  26.         $keys array_keys($event->getConfig());
  27.         foreach ($keys as $key) {
  28.             $tags[] = ThemeConfigValueAccessor::buildName($key);
  29.         }
  30.         $this->logger->invalidate($tags);
  31.     }
  32.     public function assigned(ThemeAssignedEvent $event): void
  33.     {
  34.         $this->logger->invalidate([CachedResolvedConfigLoader::buildName($event->getThemeId())]);
  35.     }
  36.     public function reset(ThemeConfigResetEvent $event): void
  37.     {
  38.         $this->logger->invalidate([CachedResolvedConfigLoader::buildName($event->getThemeId())]);
  39.     }
  40. }