src/Storefront/Theme/CachedResolvedConfigLoaderInvalidator.php line 60

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Theme;
  3. use Shopware\Core\Framework\Adapter\Cache\CacheInvalidator;
  4. use Shopware\Core\Framework\Log\Package;
  5. use Shopware\Storefront\Framework\Routing\CachedDomainLoader;
  6. use Shopware\Storefront\Theme\Event\ThemeAssignedEvent;
  7. use Shopware\Storefront\Theme\Event\ThemeConfigChangedEvent;
  8. use Shopware\Storefront\Theme\Event\ThemeConfigResetEvent;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. /**
  11.  * @internal
  12.  */
  13. #[Package('storefront')]
  14. class CachedResolvedConfigLoaderInvalidator implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @internal
  18.      */
  19.     public function __construct(private readonly CacheInvalidator $logger)
  20.     {
  21.     }
  22.     /**
  23.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  24.      */
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [
  28.             ThemeConfigChangedEvent::class => 'invalidate',
  29.             ThemeAssignedEvent::class => 'assigned',
  30.             ThemeConfigResetEvent::class => 'reset',
  31.         ];
  32.     }
  33.     public function invalidate(ThemeConfigChangedEvent $event): void
  34.     {
  35.         $tags = [CachedResolvedConfigLoader::buildName($event->getThemeId())];
  36.         $keys array_keys($event->getConfig());
  37.         foreach ($keys as $key) {
  38.             $tags[] = ThemeConfigValueAccessor::buildName($key);
  39.         }
  40.         $this->logger->invalidate($tags);
  41.     }
  42.     public function assigned(ThemeAssignedEvent $event): void
  43.     {
  44.         $this->logger->invalidate([CachedResolvedConfigLoader::buildName($event->getThemeId())]);
  45.         $this->logger->invalidate([CachedDomainLoader::CACHE_KEY]);
  46.         $salesChannelId $event->getSalesChannelId();
  47.         $this->logger->invalidate(['translation.catalog.' $salesChannelId], true);
  48.     }
  49.     public function reset(ThemeConfigResetEvent $event): void
  50.     {
  51.         $this->logger->invalidate([CachedResolvedConfigLoader::buildName($event->getThemeId())]);
  52.     }
  53. }