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

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