Blame view

vendor/symfony/cache/Marshaller/DeflateMarshaller.php 1.21 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  <?php
  
  /*
   * This file is part of the Symfony package.
   *
   * (c) Fabien Potencier <fabien@symfony.com>
   *
   * For the full copyright and license information, please view the LICENSE
   * file that was distributed with this source code.
   */
  
  namespace Symfony\Component\Cache\Marshaller;
  
  use Symfony\Component\Cache\Exception\CacheException;
  
  /**
   * Compresses values using gzdeflate().
   *
   * @author Nicolas Grekas <p@tchwork.com>
   */
  class DeflateMarshaller implements MarshallerInterface
  {
      private $marshaller;
  
      public function __construct(MarshallerInterface $marshaller)
      {
          if (!\function_exists('gzdeflate')) {
              throw new CacheException('The "zlib" PHP extension is not loaded.');
          }
  
          $this->marshaller = $marshaller;
      }
  
      /**
       * {@inheritdoc}
       */
      public function marshall(array $values, ?array &$failed): array
      {
          return array_map('gzdeflate', $this->marshaller->marshall($values, $failed));
      }
  
      /**
       * {@inheritdoc}
       */
      public function unmarshall(string $value)
      {
          if (false !== $inflatedValue = @gzinflate($value)) {
              $value = $inflatedValue;
          }
  
          return $this->marshaller->unmarshall($value);
      }
  }