vendor/shopware/storefront/Theme/CachedResolvedConfigLoader.php line 40

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Theme;
  3. use Shopware\Core\Framework\Adapter\Cache\CacheValueCompressor;
  4. use Shopware\Core\Framework\Log\Package;
  5. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  6. use Symfony\Contracts\Cache\CacheInterface;
  7. use Symfony\Contracts\Cache\ItemInterface;
  8. #[Package('storefront')]
  9. class CachedResolvedConfigLoader extends AbstractResolvedConfigLoader
  10. {
  11.     /**
  12.      * @internal
  13.      */
  14.     public function __construct(
  15.         private readonly AbstractResolvedConfigLoader $decorated,
  16.         private readonly CacheInterface $cache
  17.     ) {
  18.     }
  19.     public function getDecorated(): AbstractResolvedConfigLoader
  20.     {
  21.         return $this->decorated;
  22.     }
  23.     public function load(string $themeIdSalesChannelContext $context): array
  24.     {
  25.         $name self::buildName($themeId);
  26.         $key md5(implode('-', [$name$context->getSalesChannelId(), $context->getDomainId()]));
  27.         $value $this->cache->get($key, function (ItemInterface $item) use ($name$themeId$context) {
  28.             $config $this->getDecorated()->load($themeId$context);
  29.             $item->tag([$name]);
  30.             return CacheValueCompressor::compress($config);
  31.         });
  32.         return CacheValueCompressor::uncompress($value);
  33.     }
  34.     public static function buildName(string $themeId): string
  35.     {
  36.         return 'theme-config-' $themeId;
  37.     }
  38. }