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

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