diff options
Diffstat (limited to 'vendor/symfony/cache/Marshaller/DeflateMarshaller.php')
| -rw-r--r-- | vendor/symfony/cache/Marshaller/DeflateMarshaller.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/vendor/symfony/cache/Marshaller/DeflateMarshaller.php b/vendor/symfony/cache/Marshaller/DeflateMarshaller.php new file mode 100644 index 0000000..f35241c --- /dev/null +++ b/vendor/symfony/cache/Marshaller/DeflateMarshaller.php | |||
| @@ -0,0 +1,44 @@ | |||
| 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 | public function __construct( | ||
| 24 | private MarshallerInterface $marshaller, | ||
| 25 | ) { | ||
| 26 | if (!\function_exists('gzdeflate')) { | ||
| 27 | throw new CacheException('The "zlib" PHP extension is not loaded.'); | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | public function marshall(array $values, ?array &$failed): array | ||
| 32 | { | ||
| 33 | return array_map('gzdeflate', $this->marshaller->marshall($values, $failed)); | ||
| 34 | } | ||
| 35 | |||
| 36 | public function unmarshall(string $value): mixed | ||
| 37 | { | ||
| 38 | if (false !== $inflatedValue = @gzinflate($value)) { | ||
| 39 | $value = $inflatedValue; | ||
| 40 | } | ||
| 41 | |||
| 42 | return $this->marshaller->unmarshall($value); | ||
| 43 | } | ||
| 44 | } | ||
