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