vendor/shopware/core/Content/Seo/CachedSeoResolver.php line 43

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Seo;
  3. use Shopware\Core\Framework\Adapter\Cache\CacheValueCompressor;
  4. use Shopware\Core\Framework\Log\Package;
  5. use Symfony\Contracts\Cache\CacheInterface;
  6. use Symfony\Contracts\Cache\ItemInterface;
  7. /**
  8.  * @phpstan-import-type ResolvedSeoUrl from AbstractSeoResolver
  9.  */
  10. #[Package('sales-channel')]
  11. class CachedSeoResolver extends AbstractSeoResolver
  12. {
  13.     /**
  14.      * @internal
  15.      */
  16.     public function __construct(
  17.         private readonly AbstractSeoResolver $decorated,
  18.         private readonly CacheInterface $cache
  19.     ) {
  20.     }
  21.     public function getDecorated(): AbstractSeoResolver
  22.     {
  23.         return $this->decorated;
  24.     }
  25.     /**
  26.      * @return ResolvedSeoUrl
  27.      */
  28.     public function resolve(string $languageIdstring $salesChannelIdstring $pathInfo): array
  29.     {
  30.         $key 'seo-resolver-' md5(implode('-', [$languageId$salesChannelId$pathInfo]));
  31.         $value $this->cache->get($key, function (ItemInterface $item) use ($languageId$salesChannelId$pathInfo) {
  32.             $resolved $this->getDecorated()->resolve($languageId$salesChannelId$pathInfo);
  33.             $item->tag([self::buildName($pathInfo)]);
  34.             return CacheValueCompressor::compress($resolved);
  35.         });
  36.         /** @var ResolvedSeoUrl $value */
  37.         $value CacheValueCompressor::uncompress($value);
  38.         return $value;
  39.     }
  40.     public static function buildName(string $pathInfo): string
  41.     {
  42.         return 'path-info-' md5($pathInfo);
  43.     }
  44. }