4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Cache\Marshaller;
14 use Symfony\Component\Cache\Exception\CacheException;
17 * Compresses values using gzdeflate().
19 * @author Nicolas Grekas <p@tchwork.com>
21 class DeflateMarshaller implements MarshallerInterface
25 public function __construct(MarshallerInterface $marshaller)
27 if (!\function_exists('gzdeflate')) {
28 throw new CacheException('The "zlib" PHP extension is not loaded.');
31 $this->marshaller = $marshaller;
37 public function marshall(array $values, ?array &$failed): array
39 return array_map('gzdeflate', $this->marshaller->marshall($values, $failed));
45 public function unmarshall(string $value)
47 if (false !== $inflatedValue = @gzinflate($value)) {
48 $value = $inflatedValue;
51 return $this->marshaller->unmarshall($value);