vendor/shopware/core/Framework/Adapter/Cache/CacheValueCompressor.php line 38

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Adapter\Cache;
  3. use Shopware\Core\Framework\Log\Package;
  4. /**
  5.  * @template TCachedContent
  6.  */
  7. #[Package('core')]
  8. class CacheValueCompressor
  9. {
  10.     public static bool $compress true;
  11.     /**
  12.      * @param TCachedContent $content
  13.      */
  14.     public static function compress($content): string
  15.     {
  16.         if (!self::$compress) {
  17.             return \serialize($content);
  18.         }
  19.         $compressed gzcompress(serialize($content), 9);
  20.         if ($compressed === false) {
  21.             throw new \RuntimeException('Failed to compress cache value');
  22.         }
  23.         return $compressed;
  24.     }
  25.     /**
  26.      * @param TCachedContent|string $value
  27.      *
  28.      * @return TCachedContent
  29.      */
  30.     public static function uncompress($value)
  31.     {
  32.         if (!\is_string($value)) {
  33.             return $value;
  34.         }
  35.         if (!self::$compress) {
  36.             return \unserialize($value);
  37.         }
  38.         $uncompressed gzuncompress($value);
  39.         if ($uncompressed === false) {
  40.             throw new \RuntimeException(sprintf('Could not uncompress "%s"'$value));
  41.         }
  42.         return unserialize($uncompressed);
  43.     }
  44. }