Initial Commit
This commit is contained in:
95
dependencies/symfony/cache/Marshaller/DefaultMarshaller.php
vendored
Normal file
95
dependencies/symfony/cache/Marshaller/DefaultMarshaller.php
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
<?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 WP_Ultimo\Dependencies\Symfony\Component\Cache\Marshaller;
|
||||
|
||||
use WP_Ultimo\Dependencies\Symfony\Component\Cache\Exception\CacheException;
|
||||
/**
|
||||
* Serializes/unserializes values using igbinary_serialize() if available, serialize() otherwise.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class DefaultMarshaller implements MarshallerInterface
|
||||
{
|
||||
private $useIgbinarySerialize = \true;
|
||||
private $throwOnSerializationFailure;
|
||||
public function __construct(bool $useIgbinarySerialize = null, bool $throwOnSerializationFailure = \false)
|
||||
{
|
||||
if (null === $useIgbinarySerialize) {
|
||||
$useIgbinarySerialize = \extension_loaded('igbinary') && (\PHP_VERSION_ID < 70400 || \version_compare('3.1.6', \phpversion('igbinary'), '<='));
|
||||
} elseif ($useIgbinarySerialize && (!\extension_loaded('igbinary') || \PHP_VERSION_ID >= 70400 && \version_compare('3.1.6', \phpversion('igbinary'), '>'))) {
|
||||
throw new CacheException(\extension_loaded('igbinary') && \PHP_VERSION_ID >= 70400 ? 'Please upgrade the "igbinary" PHP extension to v3.1.6 or higher.' : 'The "igbinary" PHP extension is not loaded.');
|
||||
}
|
||||
$this->useIgbinarySerialize = $useIgbinarySerialize;
|
||||
$this->throwOnSerializationFailure = $throwOnSerializationFailure;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function marshall(array $values, ?array &$failed) : array
|
||||
{
|
||||
$serialized = $failed = [];
|
||||
foreach ($values as $id => $value) {
|
||||
try {
|
||||
if ($this->useIgbinarySerialize) {
|
||||
$serialized[$id] = \igbinary_serialize($value);
|
||||
} else {
|
||||
$serialized[$id] = \serialize($value);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if ($this->throwOnSerializationFailure) {
|
||||
throw new \ValueError($e->getMessage(), 0, $e);
|
||||
}
|
||||
$failed[] = $id;
|
||||
}
|
||||
}
|
||||
return $serialized;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function unmarshall(string $value)
|
||||
{
|
||||
if ('b:0;' === $value) {
|
||||
return \false;
|
||||
}
|
||||
if ('N;' === $value) {
|
||||
return null;
|
||||
}
|
||||
static $igbinaryNull;
|
||||
if ($value === ($igbinaryNull ?? ($igbinaryNull = \extension_loaded('igbinary') ? \igbinary_serialize(null) : \false))) {
|
||||
return null;
|
||||
}
|
||||
$unserializeCallbackHandler = \ini_set('unserialize_callback_func', __CLASS__ . '::handleUnserializeCallback');
|
||||
try {
|
||||
if (':' === ($value[1] ?? ':')) {
|
||||
if (\false !== ($value = \unserialize($value))) {
|
||||
return $value;
|
||||
}
|
||||
} elseif (\false === $igbinaryNull) {
|
||||
throw new \RuntimeException('Failed to unserialize values, did you forget to install the "igbinary" extension?');
|
||||
} elseif (null !== ($value = \igbinary_unserialize($value))) {
|
||||
return $value;
|
||||
}
|
||||
throw new \DomainException(\error_get_last() ? \error_get_last()['message'] : 'Failed to unserialize values.');
|
||||
} catch (\Error $e) {
|
||||
throw new \ErrorException($e->getMessage(), $e->getCode(), \E_ERROR, $e->getFile(), $e->getLine());
|
||||
} finally {
|
||||
\ini_set('unserialize_callback_func', $unserializeCallbackHandler);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function handleUnserializeCallback(string $class)
|
||||
{
|
||||
throw new \DomainException('Class not found: ' . $class);
|
||||
}
|
||||
}
|
46
dependencies/symfony/cache/Marshaller/DeflateMarshaller.php
vendored
Normal file
46
dependencies/symfony/cache/Marshaller/DeflateMarshaller.php
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
<?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 WP_Ultimo\Dependencies\Symfony\Component\Cache\Marshaller;
|
||||
|
||||
use WP_Ultimo\Dependencies\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);
|
||||
}
|
||||
}
|
38
dependencies/symfony/cache/Marshaller/MarshallerInterface.php
vendored
Normal file
38
dependencies/symfony/cache/Marshaller/MarshallerInterface.php
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
<?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 WP_Ultimo\Dependencies\Symfony\Component\Cache\Marshaller;
|
||||
|
||||
/**
|
||||
* Serializes/unserializes PHP values.
|
||||
*
|
||||
* Implementations of this interface MUST deal with errors carefully. They MUST
|
||||
* also deal with forward and backward compatibility at the storage format level.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
interface MarshallerInterface
|
||||
{
|
||||
/**
|
||||
* Serializes a list of values.
|
||||
*
|
||||
* When serialization fails for a specific value, no exception should be
|
||||
* thrown. Instead, its key should be listed in $failed.
|
||||
*/
|
||||
public function marshall(array $values, ?array &$failed) : array;
|
||||
/**
|
||||
* Unserializes a single value and throws an exception if anything goes wrong.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Exception Whenever unserialization fails
|
||||
*/
|
||||
public function unmarshall(string $value);
|
||||
}
|
69
dependencies/symfony/cache/Marshaller/SodiumMarshaller.php
vendored
Normal file
69
dependencies/symfony/cache/Marshaller/SodiumMarshaller.php
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
<?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 WP_Ultimo\Dependencies\Symfony\Component\Cache\Marshaller;
|
||||
|
||||
use WP_Ultimo\Dependencies\Symfony\Component\Cache\Exception\CacheException;
|
||||
use WP_Ultimo\Dependencies\Symfony\Component\Cache\Exception\InvalidArgumentException;
|
||||
/**
|
||||
* Encrypt/decrypt values using Libsodium.
|
||||
*
|
||||
* @author Ahmed TAILOULOUTE <ahmed.tailouloute@gmail.com>
|
||||
*/
|
||||
class SodiumMarshaller implements MarshallerInterface
|
||||
{
|
||||
private $marshaller;
|
||||
private $decryptionKeys;
|
||||
/**
|
||||
* @param string[] $decryptionKeys The key at index "0" is required and is used to decrypt and encrypt values;
|
||||
* more rotating keys can be provided to decrypt values;
|
||||
* each key must be generated using sodium_crypto_box_keypair()
|
||||
*/
|
||||
public function __construct(array $decryptionKeys, MarshallerInterface $marshaller = null)
|
||||
{
|
||||
if (!self::isSupported()) {
|
||||
throw new CacheException('The "sodium" PHP extension is not loaded.');
|
||||
}
|
||||
if (!isset($decryptionKeys[0])) {
|
||||
throw new InvalidArgumentException('At least one decryption key must be provided at index "0".');
|
||||
}
|
||||
$this->marshaller = $marshaller ?? new DefaultMarshaller();
|
||||
$this->decryptionKeys = $decryptionKeys;
|
||||
}
|
||||
public static function isSupported() : bool
|
||||
{
|
||||
return \function_exists('sodium_crypto_box_seal');
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function marshall(array $values, ?array &$failed) : array
|
||||
{
|
||||
$encryptionKey = \sodium_crypto_box_publickey($this->decryptionKeys[0]);
|
||||
$encryptedValues = [];
|
||||
foreach ($this->marshaller->marshall($values, $failed) as $k => $v) {
|
||||
$encryptedValues[$k] = \sodium_crypto_box_seal($v, $encryptionKey);
|
||||
}
|
||||
return $encryptedValues;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function unmarshall(string $value)
|
||||
{
|
||||
foreach ($this->decryptionKeys as $k) {
|
||||
if (\false !== ($decryptedValue = @\sodium_crypto_box_seal_open($value, $k))) {
|
||||
$value = $decryptedValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $this->marshaller->unmarshall($value);
|
||||
}
|
||||
}
|
73
dependencies/symfony/cache/Marshaller/TagAwareMarshaller.php
vendored
Normal file
73
dependencies/symfony/cache/Marshaller/TagAwareMarshaller.php
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
<?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 WP_Ultimo\Dependencies\Symfony\Component\Cache\Marshaller;
|
||||
|
||||
/**
|
||||
* A marshaller optimized for data structures generated by AbstractTagAwareAdapter.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class TagAwareMarshaller implements MarshallerInterface
|
||||
{
|
||||
private $marshaller;
|
||||
public function __construct(MarshallerInterface $marshaller = null)
|
||||
{
|
||||
$this->marshaller = $marshaller ?? new DefaultMarshaller();
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function marshall(array $values, ?array &$failed) : array
|
||||
{
|
||||
$failed = $notSerialized = $serialized = [];
|
||||
foreach ($values as $id => $value) {
|
||||
if (\is_array($value) && \is_array($value['tags'] ?? null) && \array_key_exists('value', $value) && \count($value) === 2 + (\is_string($value['meta'] ?? null) && 8 === \strlen($value['meta']))) {
|
||||
// if the value is an array with keys "tags", "value" and "meta", use a compact serialization format
|
||||
// magic numbers in the form 9D-..-..-..-..-00-..-..-..-5F allow detecting this format quickly in unmarshall()
|
||||
$v = $this->marshaller->marshall($value, $f);
|
||||
if ($f) {
|
||||
$f = [];
|
||||
$failed[] = $id;
|
||||
} else {
|
||||
if ([] === $value['tags']) {
|
||||
$v['tags'] = '';
|
||||
}
|
||||
$serialized[$id] = "\x9d" . ($value['meta'] ?? "\x00\x00\x00\x00\x00\x00\x00\x00") . \pack('N', \strlen($v['tags'])) . $v['tags'] . $v['value'];
|
||||
$serialized[$id][9] = "_";
|
||||
}
|
||||
} else {
|
||||
// other arbitrary values are serialized using the decorated marshaller below
|
||||
$notSerialized[$id] = $value;
|
||||
}
|
||||
}
|
||||
if ($notSerialized) {
|
||||
$serialized += $this->marshaller->marshall($notSerialized, $f);
|
||||
$failed = \array_merge($failed, $f);
|
||||
}
|
||||
return $serialized;
|
||||
}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function unmarshall(string $value)
|
||||
{
|
||||
// detect the compact format used in marshall() using magic numbers in the form 9D-..-..-..-..-00-..-..-..-5F
|
||||
if (13 >= \strlen($value) || "\x9d" !== $value[0] || "\x00" !== $value[5] || "_" !== $value[9]) {
|
||||
return $this->marshaller->unmarshall($value);
|
||||
}
|
||||
// data consists of value, tags and metadata which we need to unpack
|
||||
$meta = \substr($value, 1, 12);
|
||||
$meta[8] = "\x00";
|
||||
$tagLen = \unpack('Nlen', $meta, 8)['len'];
|
||||
$meta = \substr($meta, 0, 8);
|
||||
return ['value' => $this->marshaller->unmarshall(\substr($value, 13 + $tagLen)), 'tags' => $tagLen ? $this->marshaller->unmarshall(\substr($value, 13, $tagLen)) : [], 'meta' => "\x00\x00\x00\x00\x00\x00\x00\x00" === $meta ? null : $meta];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user