diff --git a/src/Symfony/Component/Cache/Adapter/ApcuAdapter.php b/src/Symfony/Component/Cache/Adapter/ApcuAdapter.php index 7db3956588..a9b599f05c 100644 --- a/src/Symfony/Component/Cache/Adapter/ApcuAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ApcuAdapter.php @@ -11,17 +11,112 @@ namespace Symfony\Component\Cache\Adapter; -use Symfony\Component\Cache\Traits\ApcuTrait; +use Symfony\Component\Cache\CacheItem; +use Symfony\Component\Cache\Exception\CacheException; +/** + * @author Nicolas Grekas
+ */ class ApcuAdapter extends AbstractAdapter { - use ApcuTrait; - /** * @throws CacheException if APCu is not enabled */ public function __construct(string $namespace = '', int $defaultLifetime = 0, string $version = null) { - $this->init($namespace, $defaultLifetime, $version); + if (!static::isSupported()) { + throw new CacheException('APCu is not enabled'); + } + if ('cli' === \PHP_SAPI) { + ini_set('apc.use_request_time', 0); + } + parent::__construct($namespace, $defaultLifetime); + + if (null !== $version) { + CacheItem::validateKey($version); + + if (!apcu_exists($version.'@'.$namespace)) { + $this->doClear($namespace); + apcu_add($version.'@'.$namespace, null); + } + } + } + + public static function isSupported() + { + return \function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN); + } + + /** + * {@inheritdoc} + */ + protected function doFetch(array $ids) + { + $unserializeCallbackHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback'); + try { + $values = []; + foreach (apcu_fetch($ids, $ok) ?: [] as $k => $v) { + if (null !== $v || $ok) { + $values[$k] = $v; + } + } + + return $values; + } catch (\Error $e) { + throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine()); + } finally { + ini_set('unserialize_callback_func', $unserializeCallbackHandler); + } + } + + /** + * {@inheritdoc} + */ + protected function doHave($id) + { + return apcu_exists($id); + } + + /** + * {@inheritdoc} + */ + protected function doClear($namespace) + { + return isset($namespace[0]) && class_exists('APCuIterator', false) && ('cli' !== \PHP_SAPI || filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN)) + ? apcu_delete(new \APCuIterator(sprintf('/^%s/', preg_quote($namespace, '/')), APC_ITER_KEY)) + : apcu_clear_cache(); + } + + /** + * {@inheritdoc} + */ + protected function doDelete(array $ids) + { + foreach ($ids as $id) { + apcu_delete($id); + } + + return true; + } + + /** + * {@inheritdoc} + */ + protected function doSave(array $values, $lifetime) + { + try { + if (false === $failures = apcu_store($values, null, $lifetime)) { + $failures = $values; + } + + return array_keys($failures); + } catch (\Throwable $e) { + if (1 === \count($values)) { + // Workaround https://github.com/krakjoe/apcu/issues/170 + apcu_delete(key($values)); + } + + throw $e; + } } } diff --git a/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php b/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php index bbb1f846e4..c356c2bbd2 100644 --- a/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php @@ -13,9 +13,9 @@ namespace Symfony\Component\Cache\Adapter; use Psr\Cache\CacheItemInterface; use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; use Symfony\Component\Cache\CacheItem; use Symfony\Component\Cache\ResettableInterface; -use Symfony\Component\Cache\Traits\ArrayTrait; use Symfony\Contracts\Cache\CacheInterface; /** @@ -23,8 +23,11 @@ use Symfony\Contracts\Cache\CacheInterface; */ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInterface, ResettableInterface { - use ArrayTrait; + use LoggerAwareTrait; + private $storeSerialized; + private $values = []; + private $expiries = []; private $createCacheItem; /** @@ -65,6 +68,27 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter return $item->get(); } + /** + * {@inheritdoc} + */ + public function delete(string $key): bool + { + return $this->deleteItem($key); + } + + /** + * {@inheritdoc} + */ + public function hasItem($key) + { + if (\is_string($key) && isset($this->expiries[$key]) && $this->expiries[$key] > microtime(true)) { + return true; + } + CacheItem::validateKey($key); + + return isset($this->expiries[$key]) && !$this->deleteItem($key); + } + /** * {@inheritdoc} */ @@ -94,6 +118,19 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter return $this->generateItems($keys, microtime(true), $this->createCacheItem); } + /** + * {@inheritdoc} + */ + public function deleteItem($key) + { + if (!\is_string($key) || !isset($this->expiries[$key])) { + CacheItem::validateKey($key); + } + unset($this->values[$key], $this->expiries[$key]); + + return true; + } + /** * {@inheritdoc} */ @@ -156,8 +193,110 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter /** * {@inheritdoc} */ - public function delete(string $key): bool + public function clear() { - return $this->deleteItem($key); + $this->values = $this->expiries = []; + + return true; + } + + /** + * Returns all cached values, with cache miss as null. + * + * @return array + */ + public function getValues() + { + if (!$this->storeSerialized) { + return $this->values; + } + + $values = $this->values; + foreach ($values as $k => $v) { + if (null === $v || 'N;' === $v) { + continue; + } + if (!\is_string($v) || !isset($v[2]) || ':' !== $v[1]) { + $values[$k] = serialize($v); + } + } + + return $values; + } + + /** + * {@inheritdoc} + */ + public function reset() + { + $this->clear(); + } + + private function generateItems(array $keys, $now, $f) + { + foreach ($keys as $i => $key) { + if (!$isHit = isset($this->expiries[$key]) && ($this->expiries[$key] > $now || !$this->deleteItem($key))) { + $this->values[$key] = $value = null; + } else { + $value = $this->storeSerialized ? $this->unfreeze($key, $isHit) : $this->values[$key]; + } + unset($keys[$i]); + + yield $key => $f($key, $value, $isHit); + } + + foreach ($keys as $key) { + yield $key => $f($key, null, false); + } + } + + private function freeze($value, $key) + { + if (null === $value) { + return 'N;'; + } + if (\is_string($value)) { + // Serialize strings if they could be confused with serialized objects or arrays + if ('N;' === $value || (isset($value[2]) && ':' === $value[1])) { + return serialize($value); + } + } elseif (!\is_scalar($value)) { + try { + $serialized = serialize($value); + } catch (\Exception $e) { + $type = \is_object($value) ? \get_class($value) : \gettype($value); + $message = sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage()); + CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e]); + + return; + } + // Keep value serialized if it contains any objects or any internal references + if ('C' === $serialized[0] || 'O' === $serialized[0] || preg_match('/;[OCRr]:[1-9]/', $serialized)) { + return $serialized; + } + } + + return $value; + } + + private function unfreeze(string $key, bool &$isHit) + { + if ('N;' === $value = $this->values[$key]) { + return null; + } + if (\is_string($value) && isset($value[2]) && ':' === $value[1]) { + try { + $value = unserialize($value); + } catch (\Exception $e) { + CacheItem::log($this->logger, 'Failed to unserialize key "{key}": '.$e->getMessage(), ['key' => $key, 'exception' => $e]); + $value = false; + } + if (false === $value) { + $this->values[$key] = $value = null; + $isHit = false; + } + } + + return $value; } } diff --git a/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php b/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php index 75ae4cb701..80a8713e0e 100644 --- a/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php @@ -12,11 +12,13 @@ namespace Symfony\Component\Cache\Adapter; use Doctrine\Common\Cache\CacheProvider; -use Symfony\Component\Cache\Traits\DoctrineTrait; +/** + * @author Nicolas Grekas
+ */
class DoctrineAdapter extends AbstractAdapter
{
- use DoctrineTrait;
+ private $provider;
public function __construct(CacheProvider $provider, string $namespace = '', int $defaultLifetime = 0)
{
@@ -24,4 +26,80 @@ class DoctrineAdapter extends AbstractAdapter
$this->provider = $provider;
$provider->setNamespace($namespace);
}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function reset()
+ {
+ parent::reset();
+ $this->provider->setNamespace($this->provider->getNamespace());
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doFetch(array $ids)
+ {
+ $unserializeCallbackHandler = ini_set('unserialize_callback_func', parent::class.'::handleUnserializeCallback');
+ try {
+ return $this->provider->fetchMultiple($ids);
+ } catch (\Error $e) {
+ $trace = $e->getTrace();
+
+ if (isset($trace[0]['function']) && !isset($trace[0]['class'])) {
+ switch ($trace[0]['function']) {
+ case 'unserialize':
+ case 'apcu_fetch':
+ case 'apc_fetch':
+ throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
+ }
+ }
+
+ throw $e;
+ } finally {
+ ini_set('unserialize_callback_func', $unserializeCallbackHandler);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doHave($id)
+ {
+ return $this->provider->contains($id);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doClear($namespace)
+ {
+ $namespace = $this->provider->getNamespace();
+
+ return isset($namespace[0])
+ ? $this->provider->deleteAll()
+ : $this->provider->flushAll();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doDelete(array $ids)
+ {
+ $ok = true;
+ foreach ($ids as $id) {
+ $ok = $this->provider->delete($id) && $ok;
+ }
+
+ return $ok;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doSave(array $values, $lifetime)
+ {
+ return $this->provider->saveMultiple($values, $lifetime);
+ }
}
diff --git a/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php b/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php
index b678bb5d88..ce29d84bf2 100644
--- a/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php
+++ b/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php
@@ -11,15 +11,30 @@
namespace Symfony\Component\Cache\Adapter;
+use Symfony\Component\Cache\Exception\CacheException;
+use Symfony\Component\Cache\Exception\InvalidArgumentException;
+use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
-use Symfony\Component\Cache\Traits\MemcachedTrait;
+/**
+ * @author Rob Frawley 2nd
+ */
class MemcachedAdapter extends AbstractAdapter
{
- use MemcachedTrait;
-
protected $maxIdLength = 250;
+ private static $defaultClientOptions = [
+ 'persistent_id' => null,
+ 'username' => null,
+ 'password' => null,
+ 'serializer' => 'php',
+ ];
+
+ private $marshaller;
+ private $client;
+ private $lazyClient;
+
/**
* Using a MemcachedAdapter with a TagAwareAdapter for storing tags is discouraged.
* Using a RedisAdapter is recommended instead. If you cannot do otherwise, be aware that:
@@ -32,6 +47,292 @@ class MemcachedAdapter extends AbstractAdapter
*/
public function __construct(\Memcached $client, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
{
- $this->init($client, $namespace, $defaultLifetime, $marshaller);
+ if (!static::isSupported()) {
+ throw new CacheException('Memcached >= 2.2.0 is required');
+ }
+ if ('Memcached' === \get_class($client)) {
+ $opt = $client->getOption(\Memcached::OPT_SERIALIZER);
+ if (\Memcached::SERIALIZER_PHP !== $opt && \Memcached::SERIALIZER_IGBINARY !== $opt) {
+ throw new CacheException('MemcachedAdapter: "serializer" option must be "php" or "igbinary".');
+ }
+ $this->maxIdLength -= \strlen($client->getOption(\Memcached::OPT_PREFIX_KEY));
+ $this->client = $client;
+ } else {
+ $this->lazyClient = $client;
+ }
+
+ parent::__construct($namespace, $defaultLifetime);
+ $this->enableVersioning();
+ $this->marshaller = $marshaller ?? new DefaultMarshaller();
+ }
+
+ public static function isSupported()
+ {
+ return \extension_loaded('memcached') && version_compare(phpversion('memcached'), '2.2.0', '>=');
+ }
+
+ /**
+ * Creates a Memcached instance.
+ *
+ * By default, the binary protocol, no block, and libketama compatible options are enabled.
+ *
+ * Examples for servers:
+ * - 'memcached://user:pass@localhost?weight=33'
+ * - [['localhost', 11211, 33]]
+ *
+ * @param array[]|string|string[] $servers An array of servers, a DSN, or an array of DSNs
+ * @param array $options An array of options
+ *
+ * @return \Memcached
+ *
+ * @throws \ErrorException When invalid options or servers are provided
+ */
+ public static function createConnection($servers, array $options = [])
+ {
+ if (\is_string($servers)) {
+ $servers = [$servers];
+ } elseif (!\is_array($servers)) {
+ throw new InvalidArgumentException(sprintf('MemcachedAdapter::createClient() expects array or string as first argument, %s given.', \gettype($servers)));
+ }
+ if (!static::isSupported()) {
+ throw new CacheException('Memcached >= 2.2.0 is required');
+ }
+ set_error_handler(function ($type, $msg, $file, $line) { throw new \ErrorException($msg, 0, $type, $file, $line); });
+ try {
+ $options += static::$defaultClientOptions;
+ $client = new \Memcached($options['persistent_id']);
+ $username = $options['username'];
+ $password = $options['password'];
+
+ // parse any DSN in $servers
+ foreach ($servers as $i => $dsn) {
+ if (\is_array($dsn)) {
+ continue;
+ }
+ if (0 !== strpos($dsn, 'memcached:')) {
+ throw new InvalidArgumentException(sprintf('Invalid Memcached DSN: %s does not start with "memcached:"', $dsn));
+ }
+ $params = preg_replace_callback('#^memcached:(//)?(?:([^@]*+)@)?#', function ($m) use (&$username, &$password) {
+ if (!empty($m[2])) {
+ list($username, $password) = explode(':', $m[2], 2) + [1 => null];
+ }
+
+ return 'file:'.($m[1] ?? '');
+ }, $dsn);
+ if (false === $params = parse_url($params)) {
+ throw new InvalidArgumentException(sprintf('Invalid Memcached DSN: %s', $dsn));
+ }
+ $query = $hosts = [];
+ if (isset($params['query'])) {
+ parse_str($params['query'], $query);
+
+ if (isset($query['host'])) {
+ if (!\is_array($hosts = $query['host'])) {
+ throw new InvalidArgumentException(sprintf('Invalid Memcached DSN: %s', $dsn));
+ }
+ foreach ($hosts as $host => $weight) {
+ if (false === $port = strrpos($host, ':')) {
+ $hosts[$host] = [$host, 11211, (int) $weight];
+ } else {
+ $hosts[$host] = [substr($host, 0, $port), (int) substr($host, 1 + $port), (int) $weight];
+ }
+ }
+ $hosts = array_values($hosts);
+ unset($query['host']);
+ }
+ if ($hosts && !isset($params['host']) && !isset($params['path'])) {
+ unset($servers[$i]);
+ $servers = array_merge($servers, $hosts);
+ continue;
+ }
+ }
+ if (!isset($params['host']) && !isset($params['path'])) {
+ throw new InvalidArgumentException(sprintf('Invalid Memcached DSN: %s', $dsn));
+ }
+ if (isset($params['path']) && preg_match('#/(\d+)$#', $params['path'], $m)) {
+ $params['weight'] = $m[1];
+ $params['path'] = substr($params['path'], 0, -\strlen($m[0]));
+ }
+ $params += [
+ 'host' => isset($params['host']) ? $params['host'] : $params['path'],
+ 'port' => isset($params['host']) ? 11211 : null,
+ 'weight' => 0,
+ ];
+ if ($query) {
+ $params += $query;
+ $options = $query + $options;
+ }
+
+ $servers[$i] = [$params['host'], $params['port'], $params['weight']];
+
+ if ($hosts) {
+ $servers = array_merge($servers, $hosts);
+ }
+ }
+
+ // set client's options
+ unset($options['persistent_id'], $options['username'], $options['password'], $options['weight'], $options['lazy']);
+ $options = array_change_key_case($options, CASE_UPPER);
+ $client->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
+ $client->setOption(\Memcached::OPT_NO_BLOCK, true);
+ $client->setOption(\Memcached::OPT_TCP_NODELAY, true);
+ if (!\array_key_exists('LIBKETAMA_COMPATIBLE', $options) && !\array_key_exists(\Memcached::OPT_LIBKETAMA_COMPATIBLE, $options)) {
+ $client->setOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
+ }
+ foreach ($options as $name => $value) {
+ if (\is_int($name)) {
+ continue;
+ }
+ if ('HASH' === $name || 'SERIALIZER' === $name || 'DISTRIBUTION' === $name) {
+ $value = \constant('Memcached::'.$name.'_'.strtoupper($value));
+ }
+ $opt = \constant('Memcached::OPT_'.$name);
+
+ unset($options[$name]);
+ $options[$opt] = $value;
+ }
+ $client->setOptions($options);
+
+ // set client's servers, taking care of persistent connections
+ if (!$client->isPristine()) {
+ $oldServers = [];
+ foreach ($client->getServerList() as $server) {
+ $oldServers[] = [$server['host'], $server['port']];
+ }
+
+ $newServers = [];
+ foreach ($servers as $server) {
+ if (1 < \count($server)) {
+ $server = array_values($server);
+ unset($server[2]);
+ $server[1] = (int) $server[1];
+ }
+ $newServers[] = $server;
+ }
+
+ if ($oldServers !== $newServers) {
+ $client->resetServerList();
+ $client->addServers($servers);
+ }
+ } else {
+ $client->addServers($servers);
+ }
+
+ if (null !== $username || null !== $password) {
+ if (!method_exists($client, 'setSaslAuthData')) {
+ trigger_error('Missing SASL support: the memcached extension must be compiled with --enable-memcached-sasl.');
+ }
+ $client->setSaslAuthData($username, $password);
+ }
+
+ return $client;
+ } finally {
+ restore_error_handler();
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doSave(array $values, $lifetime)
+ {
+ if (!$values = $this->marshaller->marshall($values, $failed)) {
+ return $failed;
+ }
+
+ if ($lifetime && $lifetime > 30 * 86400) {
+ $lifetime += time();
+ }
+
+ $encodedValues = [];
+ foreach ($values as $key => $value) {
+ $encodedValues[rawurlencode($key)] = $value;
+ }
+
+ return $this->checkResultCode($this->getClient()->setMulti($encodedValues, $lifetime)) ? $failed : false;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doFetch(array $ids)
+ {
+ try {
+ $encodedIds = array_map('rawurlencode', $ids);
+
+ $encodedResult = $this->checkResultCode($this->getClient()->getMulti($encodedIds));
+
+ $result = [];
+ foreach ($encodedResult as $key => $value) {
+ $result[rawurldecode($key)] = $this->marshaller->unmarshall($value);
+ }
+
+ return $result;
+ } catch (\Error $e) {
+ throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doHave($id)
+ {
+ return false !== $this->getClient()->get(rawurlencode($id)) || $this->checkResultCode(\Memcached::RES_SUCCESS === $this->client->getResultCode());
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doDelete(array $ids)
+ {
+ $ok = true;
+ $encodedIds = array_map('rawurlencode', $ids);
+ foreach ($this->checkResultCode($this->getClient()->deleteMulti($encodedIds)) as $result) {
+ if (\Memcached::RES_SUCCESS !== $result && \Memcached::RES_NOTFOUND !== $result) {
+ $ok = false;
+ }
+ }
+
+ return $ok;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doClear($namespace)
+ {
+ return '' === $namespace && $this->getClient()->flush();
+ }
+
+ private function checkResultCode($result)
+ {
+ $code = $this->client->getResultCode();
+
+ if (\Memcached::RES_SUCCESS === $code || \Memcached::RES_NOTFOUND === $code) {
+ return $result;
+ }
+
+ throw new CacheException(sprintf('MemcachedAdapter client error: %s.', strtolower($this->client->getResultMessage())));
+ }
+
+ /**
+ * @return \Memcached
+ */
+ private function getClient()
+ {
+ if ($this->client) {
+ return $this->client;
+ }
+
+ $opt = $this->lazyClient->getOption(\Memcached::OPT_SERIALIZER);
+ if (\Memcached::SERIALIZER_PHP !== $opt && \Memcached::SERIALIZER_IGBINARY !== $opt) {
+ throw new CacheException('MemcachedAdapter: "serializer" option must be "php" or "igbinary".');
+ }
+ if ('' !== $prefix = (string) $this->lazyClient->getOption(\Memcached::OPT_PREFIX_KEY)) {
+ throw new CacheException(sprintf('MemcachedAdapter: "prefix_key" option must be empty when using proxified connections, "%s" given.', $prefix));
+ }
+
+ return $this->client = $this->lazyClient;
}
}
diff --git a/src/Symfony/Component/Cache/Adapter/PdoAdapter.php b/src/Symfony/Component/Cache/Adapter/PdoAdapter.php
index d118736aec..2bb4c4df6c 100644
--- a/src/Symfony/Component/Cache/Adapter/PdoAdapter.php
+++ b/src/Symfony/Component/Cache/Adapter/PdoAdapter.php
@@ -12,17 +12,34 @@
namespace Symfony\Component\Cache\Adapter;
use Doctrine\DBAL\Connection;
+use Doctrine\DBAL\DBALException;
+use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
+use Doctrine\DBAL\Exception\TableNotFoundException;
+use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\Cache\Exception\InvalidArgumentException;
+use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
use Symfony\Component\Cache\PruneableInterface;
-use Symfony\Component\Cache\Traits\PdoTrait;
class PdoAdapter extends AbstractAdapter implements PruneableInterface
{
- use PdoTrait;
-
protected $maxIdLength = 255;
+ private $marshaller;
+ private $conn;
+ private $dsn;
+ private $driver;
+ private $serverVersion;
+ private $table = 'cache_items';
+ private $idCol = 'item_id';
+ private $dataCol = 'item_data';
+ private $lifetimeCol = 'item_lifetime';
+ private $timeCol = 'item_time';
+ private $username = '';
+ private $password = '';
+ private $connectionOptions = [];
+ private $namespace;
+
/**
* You can either pass an existing database connection as PDO instance or
* a Doctrine DBAL Connection or a DSN string that will be used to
@@ -49,6 +66,380 @@ class PdoAdapter extends AbstractAdapter implements PruneableInterface
*/
public function __construct($connOrDsn, string $namespace = '', int $defaultLifetime = 0, array $options = [], MarshallerInterface $marshaller = null)
{
- $this->init($connOrDsn, $namespace, $defaultLifetime, $options, $marshaller);
+ if (isset($namespace[0]) && preg_match('#[^-+.A-Za-z0-9]#', $namespace, $match)) {
+ throw new InvalidArgumentException(sprintf('Namespace contains "%s" but only characters in [-+.A-Za-z0-9] are allowed.', $match[0]));
+ }
+
+ if ($connOrDsn instanceof \PDO) {
+ if (\PDO::ERRMODE_EXCEPTION !== $connOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) {
+ throw new InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION))', __CLASS__));
+ }
+
+ $this->conn = $connOrDsn;
+ } elseif ($connOrDsn instanceof Connection) {
+ $this->conn = $connOrDsn;
+ } elseif (\is_string($connOrDsn)) {
+ $this->dsn = $connOrDsn;
+ } else {
+ throw new InvalidArgumentException(sprintf('"%s" requires PDO or Doctrine\DBAL\Connection instance or DSN string as first argument, "%s" given.', __CLASS__, \is_object($connOrDsn) ? \get_class($connOrDsn) : \gettype($connOrDsn)));
+ }
+
+ $this->table = isset($options['db_table']) ? $options['db_table'] : $this->table;
+ $this->idCol = isset($options['db_id_col']) ? $options['db_id_col'] : $this->idCol;
+ $this->dataCol = isset($options['db_data_col']) ? $options['db_data_col'] : $this->dataCol;
+ $this->lifetimeCol = isset($options['db_lifetime_col']) ? $options['db_lifetime_col'] : $this->lifetimeCol;
+ $this->timeCol = isset($options['db_time_col']) ? $options['db_time_col'] : $this->timeCol;
+ $this->username = isset($options['db_username']) ? $options['db_username'] : $this->username;
+ $this->password = isset($options['db_password']) ? $options['db_password'] : $this->password;
+ $this->connectionOptions = isset($options['db_connection_options']) ? $options['db_connection_options'] : $this->connectionOptions;
+ $this->namespace = $namespace;
+ $this->marshaller = $marshaller ?? new DefaultMarshaller();
+
+ parent::__construct($namespace, $defaultLifetime);
+ }
+
+ /**
+ * Creates the table to store cache items which can be called once for setup.
+ *
+ * Cache ID are saved in a column of maximum length 255. Cache data is
+ * saved in a BLOB.
+ *
+ * @throws \PDOException When the table already exists
+ * @throws DBALException When the table already exists
+ * @throws \DomainException When an unsupported PDO driver is used
+ */
+ public function createTable()
+ {
+ // connect if we are not yet
+ $conn = $this->getConnection();
+
+ if ($conn instanceof Connection) {
+ $types = [
+ 'mysql' => 'binary',
+ 'sqlite' => 'text',
+ 'pgsql' => 'string',
+ 'oci' => 'string',
+ 'sqlsrv' => 'string',
+ ];
+ if (!isset($types[$this->driver])) {
+ throw new \DomainException(sprintf('Creating the cache table is currently not implemented for PDO driver "%s".', $this->driver));
+ }
+
+ $schema = new Schema();
+ $table = $schema->createTable($this->table);
+ $table->addColumn($this->idCol, $types[$this->driver], ['length' => 255]);
+ $table->addColumn($this->dataCol, 'blob', ['length' => 16777215]);
+ $table->addColumn($this->lifetimeCol, 'integer', ['unsigned' => true, 'notnull' => false]);
+ $table->addColumn($this->timeCol, 'integer', ['unsigned' => true]);
+ $table->setPrimaryKey([$this->idCol]);
+
+ foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) {
+ $conn->exec($sql);
+ }
+
+ return;
+ }
+
+ switch ($this->driver) {
+ case 'mysql':
+ // We use varbinary for the ID column because it prevents unwanted conversions:
+ // - character set conversions between server and client
+ // - trailing space removal
+ // - case-insensitivity
+ // - language processing like é == e
+ $sql = "CREATE TABLE $this->table ($this->idCol VARBINARY(255) NOT NULL PRIMARY KEY, $this->dataCol MEDIUMBLOB NOT NULL, $this->lifetimeCol INTEGER UNSIGNED, $this->timeCol INTEGER UNSIGNED NOT NULL) COLLATE utf8_bin, ENGINE = InnoDB";
+ break;
+ case 'sqlite':
+ $sql = "CREATE TABLE $this->table ($this->idCol TEXT NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
+ break;
+ case 'pgsql':
+ $sql = "CREATE TABLE $this->table ($this->idCol VARCHAR(255) NOT NULL PRIMARY KEY, $this->dataCol BYTEA NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
+ break;
+ case 'oci':
+ $sql = "CREATE TABLE $this->table ($this->idCol VARCHAR2(255) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
+ break;
+ case 'sqlsrv':
+ $sql = "CREATE TABLE $this->table ($this->idCol VARCHAR(255) NOT NULL PRIMARY KEY, $this->dataCol VARBINARY(MAX) NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
+ break;
+ default:
+ throw new \DomainException(sprintf('Creating the cache table is currently not implemented for PDO driver "%s".', $this->driver));
+ }
+
+ $conn->exec($sql);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function prune()
+ {
+ $deleteSql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= :time";
+
+ if ('' !== $this->namespace) {
+ $deleteSql .= " AND $this->idCol LIKE :namespace";
+ }
+
+ try {
+ $delete = $this->getConnection()->prepare($deleteSql);
+ } catch (TableNotFoundException $e) {
+ return true;
+ }
+ $delete->bindValue(':time', time(), \PDO::PARAM_INT);
+
+ if ('' !== $this->namespace) {
+ $delete->bindValue(':namespace', sprintf('%s%%', $this->namespace), \PDO::PARAM_STR);
+ }
+ try {
+ return $delete->execute();
+ } catch (TableNotFoundException $e) {
+ return true;
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doFetch(array $ids)
+ {
+ $now = time();
+ $expired = [];
+
+ $sql = str_pad('', (\count($ids) << 1) - 1, '?,');
+ $sql = "SELECT $this->idCol, CASE WHEN $this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > ? THEN $this->dataCol ELSE NULL END FROM $this->table WHERE $this->idCol IN ($sql)";
+ $stmt = $this->getConnection()->prepare($sql);
+ $stmt->bindValue($i = 1, $now, \PDO::PARAM_INT);
+ foreach ($ids as $id) {
+ $stmt->bindValue(++$i, $id);
+ }
+ $stmt->execute();
+
+ while ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
+ if (null === $row[1]) {
+ $expired[] = $row[0];
+ } else {
+ yield $row[0] => $this->marshaller->unmarshall(\is_resource($row[1]) ? stream_get_contents($row[1]) : $row[1]);
+ }
+ }
+
+ if ($expired) {
+ $sql = str_pad('', (\count($expired) << 1) - 1, '?,');
+ $sql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= ? AND $this->idCol IN ($sql)";
+ $stmt = $this->getConnection()->prepare($sql);
+ $stmt->bindValue($i = 1, $now, \PDO::PARAM_INT);
+ foreach ($expired as $id) {
+ $stmt->bindValue(++$i, $id);
+ }
+ $stmt->execute();
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doHave($id)
+ {
+ $sql = "SELECT 1 FROM $this->table WHERE $this->idCol = :id AND ($this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > :time)";
+ $stmt = $this->getConnection()->prepare($sql);
+
+ $stmt->bindValue(':id', $id);
+ $stmt->bindValue(':time', time(), \PDO::PARAM_INT);
+ $stmt->execute();
+
+ return (bool) $stmt->fetchColumn();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doClear($namespace)
+ {
+ $conn = $this->getConnection();
+
+ if ('' === $namespace) {
+ if ('sqlite' === $this->driver) {
+ $sql = "DELETE FROM $this->table";
+ } else {
+ $sql = "TRUNCATE TABLE $this->table";
+ }
+ } else {
+ $sql = "DELETE FROM $this->table WHERE $this->idCol LIKE '$namespace%'";
+ }
+
+ try {
+ $conn->exec($sql);
+ } catch (TableNotFoundException $e) {
+ }
+
+ return true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doDelete(array $ids)
+ {
+ $sql = str_pad('', (\count($ids) << 1) - 1, '?,');
+ $sql = "DELETE FROM $this->table WHERE $this->idCol IN ($sql)";
+ try {
+ $stmt = $this->getConnection()->prepare($sql);
+ $stmt->execute(array_values($ids));
+ } catch (TableNotFoundException $e) {
+ }
+
+ return true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function doSave(array $values, $lifetime)
+ {
+ if (!$values = $this->marshaller->marshall($values, $failed)) {
+ return $failed;
+ }
+
+ $conn = $this->getConnection();
+ $driver = $this->driver;
+ $insertSql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time)";
+
+ switch (true) {
+ case 'mysql' === $driver:
+ $sql = $insertSql." ON DUPLICATE KEY UPDATE $this->dataCol = VALUES($this->dataCol), $this->lifetimeCol = VALUES($this->lifetimeCol), $this->timeCol = VALUES($this->timeCol)";
+ break;
+ case 'oci' === $driver:
+ // DUAL is Oracle specific dummy table
+ $sql = "MERGE INTO $this->table USING DUAL ON ($this->idCol = ?) ".
+ "WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?) ".
+ "WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?";
+ break;
+ case 'sqlsrv' === $driver && version_compare($this->getServerVersion(), '10', '>='):
+ // MERGE is only available since SQL Server 2008 and must be terminated by semicolon
+ // It also requires HOLDLOCK according to http://weblogs.sqlteam.com/dang/archive/2009/01/31/UPSERT-Race-Condition-With-MERGE.aspx
+ $sql = "MERGE INTO $this->table WITH (HOLDLOCK) USING (SELECT 1 AS dummy) AS src ON ($this->idCol = ?) ".
+ "WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?) ".
+ "WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?;";
+ break;
+ case 'sqlite' === $driver:
+ $sql = 'INSERT OR REPLACE'.substr($insertSql, 6);
+ break;
+ case 'pgsql' === $driver && version_compare($this->getServerVersion(), '9.5', '>='):
+ $sql = $insertSql." ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->lifetimeCol, $this->timeCol) = (EXCLUDED.$this->dataCol, EXCLUDED.$this->lifetimeCol, EXCLUDED.$this->timeCol)";
+ break;
+ default:
+ $driver = null;
+ $sql = "UPDATE $this->table SET $this->dataCol = :data, $this->lifetimeCol = :lifetime, $this->timeCol = :time WHERE $this->idCol = :id";
+ break;
+ }
+
+ $now = time();
+ $lifetime = $lifetime ?: null;
+ try {
+ $stmt = $conn->prepare($sql);
+ } catch (TableNotFoundException $e) {
+ if (!$conn->isTransactionActive() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
+ $this->createTable();
+ }
+ $stmt = $conn->prepare($sql);
+ }
+
+ if ('sqlsrv' === $driver || 'oci' === $driver) {
+ $stmt->bindParam(1, $id);
+ $stmt->bindParam(2, $id);
+ $stmt->bindParam(3, $data, \PDO::PARAM_LOB);
+ $stmt->bindValue(4, $lifetime, \PDO::PARAM_INT);
+ $stmt->bindValue(5, $now, \PDO::PARAM_INT);
+ $stmt->bindParam(6, $data, \PDO::PARAM_LOB);
+ $stmt->bindValue(7, $lifetime, \PDO::PARAM_INT);
+ $stmt->bindValue(8, $now, \PDO::PARAM_INT);
+ } else {
+ $stmt->bindParam(':id', $id);
+ $stmt->bindParam(':data', $data, \PDO::PARAM_LOB);
+ $stmt->bindValue(':lifetime', $lifetime, \PDO::PARAM_INT);
+ $stmt->bindValue(':time', $now, \PDO::PARAM_INT);
+ }
+ if (null === $driver) {
+ $insertStmt = $conn->prepare($insertSql);
+
+ $insertStmt->bindParam(':id', $id);
+ $insertStmt->bindParam(':data', $data, \PDO::PARAM_LOB);
+ $insertStmt->bindValue(':lifetime', $lifetime, \PDO::PARAM_INT);
+ $insertStmt->bindValue(':time', $now, \PDO::PARAM_INT);
+ }
+
+ foreach ($values as $id => $data) {
+ try {
+ $stmt->execute();
+ } catch (TableNotFoundException $e) {
+ if (!$conn->isTransactionActive() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
+ $this->createTable();
+ }
+ $stmt->execute();
+ }
+ if (null === $driver && !$stmt->rowCount()) {
+ try {
+ $insertStmt->execute();
+ } catch (DBALException $e) {
+ } catch (\PDOException $e) {
+ // A concurrent write won, let it be
+ }
+ }
+ }
+
+ return $failed;
+ }
+
+ /**
+ * @return \PDO|Connection
+ */
+ private function getConnection()
+ {
+ if (null === $this->conn) {
+ $this->conn = new \PDO($this->dsn, $this->username, $this->password, $this->connectionOptions);
+ $this->conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
+ }
+ if (null === $this->driver) {
+ if ($this->conn instanceof \PDO) {
+ $this->driver = $this->conn->getAttribute(\PDO::ATTR_DRIVER_NAME);
+ } else {
+ switch ($this->driver = $this->conn->getDriver()->getName()) {
+ case 'mysqli':
+ case 'pdo_mysql':
+ case 'drizzle_pdo_mysql':
+ $this->driver = 'mysql';
+ break;
+ case 'pdo_sqlite':
+ $this->driver = 'sqlite';
+ break;
+ case 'pdo_pgsql':
+ $this->driver = 'pgsql';
+ break;
+ case 'oci8':
+ case 'pdo_oracle':
+ $this->driver = 'oci';
+ break;
+ case 'pdo_sqlsrv':
+ $this->driver = 'sqlsrv';
+ break;
+ }
+ }
+ }
+
+ return $this->conn;
+ }
+
+ private function getServerVersion(): string
+ {
+ if (null === $this->serverVersion) {
+ $conn = $this->conn instanceof \PDO ? $this->conn : $this->conn->getWrappedConnection();
+ if ($conn instanceof \PDO) {
+ $this->serverVersion = $conn->getAttribute(\PDO::ATTR_SERVER_VERSION);
+ } elseif ($conn instanceof ServerInfoAwareConnection) {
+ $this->serverVersion = $conn->getServerVersion();
+ } else {
+ $this->serverVersion = '0';
+ }
+ }
+
+ return $this->serverVersion;
}
}
diff --git a/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php b/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
index 129a9e7df4..038d4ee37f 100644
--- a/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
+++ b/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
@@ -18,7 +18,8 @@ use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Component\Cache\Traits\ContractsTrait;
-use Symfony\Component\Cache\Traits\PhpArrayTrait;
+use Symfony\Component\Cache\Traits\ProxyTrait;
+use Symfony\Component\VarExporter\VarExporter;
use Symfony\Contracts\Cache\CacheInterface;
/**
@@ -30,9 +31,12 @@ use Symfony\Contracts\Cache\CacheInterface;
*/
class PhpArrayAdapter implements AdapterInterface, CacheInterface, PruneableInterface, ResettableInterface
{
- use PhpArrayTrait;
use ContractsTrait;
+ use ProxyTrait;
+ private $file;
+ private $keys;
+ private $values;
private $createCacheItem;
/**
@@ -255,6 +259,127 @@ class PhpArrayAdapter implements AdapterInterface, CacheInterface, PruneableInte
return $this->pool->commit();
}
+ /**
+ * {@inheritdoc}
+ */
+ public function clear()
+ {
+ $this->keys = $this->values = [];
+
+ $cleared = @unlink($this->file) || !file_exists($this->file);
+
+ return $this->pool->clear() && $cleared;
+ }
+
+ /**
+ * Store an array of cached values.
+ *
+ * @param array $values The cached values
+ */
+ public function warmUp(array $values)
+ {
+ if (file_exists($this->file)) {
+ if (!is_file($this->file)) {
+ throw new InvalidArgumentException(sprintf('Cache path exists and is not a file: %s.', $this->file));
+ }
+
+ if (!is_writable($this->file)) {
+ throw new InvalidArgumentException(sprintf('Cache file is not writable: %s.', $this->file));
+ }
+ } else {
+ $directory = \dirname($this->file);
+
+ if (!is_dir($directory) && !@mkdir($directory, 0777, true)) {
+ throw new InvalidArgumentException(sprintf('Cache directory does not exist and cannot be created: %s.', $directory));
+ }
+
+ if (!is_writable($directory)) {
+ throw new InvalidArgumentException(sprintf('Cache directory is not writable: %s.', $directory));
+ }
+ }
+
+ $dumpedValues = '';
+ $dumpedMap = [];
+ $dump = <<<'EOF'
+ $value) {
+ CacheItem::validateKey(\is_int($key) ? (string) $key : $key);
+ $isStaticValue = true;
+
+ if (null === $value) {
+ $value = "'N;'";
+ } elseif (\is_object($value) || \is_array($value)) {
+ try {
+ $value = VarExporter::export($value, $isStaticValue);
+ } catch (\Exception $e) {
+ throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, \is_object($value) ? \get_class($value) : 'array'), 0, $e);
+ }
+ } elseif (\is_string($value)) {
+ // Wrap "N;" in a closure to not confuse it with an encoded `null`
+ if ('N;' === $value) {
+ $isStaticValue = false;
+ }
+ $value = var_export($value, true);
+ } elseif (!\is_scalar($value)) {
+ throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, \gettype($value)));
+ } else {
+ $value = var_export($value, true);
+ }
+
+ if (!$isStaticValue) {
+ $value = str_replace("\n", "\n ", $value);
+ $value = "static function () {\n return {$value};\n}";
+ }
+ $hash = hash('md5', $value);
+
+ if (null === $id = $dumpedMap[$hash] ?? null) {
+ $id = $dumpedMap[$hash] = \count($dumpedMap);
+ $dumpedValues .= "{$id} => {$value},\n";
+ }
+
+ $dump .= var_export($key, true)." => {$id},\n";
+ }
+
+ $dump .= "\n], [\n\n{$dumpedValues}\n]];\n";
+
+ $tmpFile = uniqid($this->file, true);
+
+ file_put_contents($tmpFile, $dump);
+ @chmod($tmpFile, 0666 & ~umask());
+ unset($serialized, $value, $dump);
+
+ @rename($tmpFile, $this->file);
+
+ $this->initialize();
+ }
+
+ /**
+ * Load the cache file.
+ */
+ private function initialize()
+ {
+ if (!file_exists($this->file)) {
+ $this->keys = $this->values = [];
+
+ return;
+ }
+ $values = (include $this->file) ?: [[], []];
+
+ if (2 !== \count($values) || !isset($values[0], $values[1])) {
+ $this->keys = $this->values = [];
+ } else {
+ list($this->keys, $this->values) = $values;
+ }
+ }
+
private function generateItems(array $keys): \Generator
{
$f = $this->createCacheItem;
diff --git a/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php b/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php
index 10938a0a9e..095350eb1b 100644
--- a/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php
+++ b/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php
@@ -12,12 +12,29 @@
namespace Symfony\Component\Cache\Adapter;
use Symfony\Component\Cache\Exception\CacheException;
+use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\PruneableInterface;
-use Symfony\Component\Cache\Traits\PhpFilesTrait;
+use Symfony\Component\Cache\Traits\FilesystemCommonTrait;
+use Symfony\Component\VarExporter\VarExporter;
+/**
+ * @author Piotr Stankowski
+ * @author Rob Frawley 2nd
- *
- * @internal
- */
-trait AbstractTrait
-{
- use LoggerAwareTrait;
-
- private $namespace;
- private $namespaceVersion = '';
- private $versioningIsEnabled = false;
- private $deferred = [];
- private $ids = [];
-
- /**
- * @var int|null The maximum length to enforce for identifiers or null when no limit applies
- */
- protected $maxIdLength;
-
- /**
- * Fetches several cache items.
- *
- * @param array $ids The cache identifiers to fetch
- *
- * @return array|\Traversable The corresponding values found in the cache
- */
- abstract protected function doFetch(array $ids);
-
- /**
- * Confirms if the cache contains specified cache item.
- *
- * @param string $id The identifier for which to check existence
- *
- * @return bool True if item exists in the cache, false otherwise
- */
- abstract protected function doHave($id);
-
- /**
- * Deletes all items in the pool.
- *
- * @param string $namespace The prefix used for all identifiers managed by this pool
- *
- * @return bool True if the pool was successfully cleared, false otherwise
- */
- abstract protected function doClear($namespace);
-
- /**
- * Removes multiple items from the pool.
- *
- * @param array $ids An array of identifiers that should be removed from the pool
- *
- * @return bool True if the items were successfully removed, false otherwise
- */
- abstract protected function doDelete(array $ids);
-
- /**
- * Persists several cache items immediately.
- *
- * @param array $values The values to cache, indexed by their cache identifier
- * @param int $lifetime The lifetime of the cached values, 0 for persisting until manual cleaning
- *
- * @return array|bool The identifiers that failed to be cached or a boolean stating if caching succeeded or not
- */
- abstract protected function doSave(array $values, $lifetime);
-
- /**
- * {@inheritdoc}
- */
- public function hasItem($key)
- {
- $id = $this->getId($key);
-
- if (isset($this->deferred[$key])) {
- $this->commit();
- }
-
- try {
- return $this->doHave($id);
- } catch (\Exception $e) {
- CacheItem::log($this->logger, 'Failed to check if key "{key}" is cached: '.$e->getMessage(), ['key' => $key, 'exception' => $e]);
-
- return false;
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function clear()
- {
- $this->deferred = [];
- if ($cleared = $this->versioningIsEnabled) {
- $namespaceVersion = substr_replace(base64_encode(pack('V', mt_rand())), ':', 5);
- try {
- $cleared = $this->doSave(['/'.$this->namespace => $namespaceVersion], 0);
- } catch (\Exception $e) {
- $cleared = false;
- }
- if ($cleared = true === $cleared || [] === $cleared) {
- $this->namespaceVersion = $namespaceVersion;
- $this->ids = [];
- }
- }
-
- try {
- return $this->doClear($this->namespace) || $cleared;
- } catch (\Exception $e) {
- CacheItem::log($this->logger, 'Failed to clear the cache: '.$e->getMessage(), ['exception' => $e]);
-
- return false;
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function deleteItem($key)
- {
- return $this->deleteItems([$key]);
- }
-
- /**
- * {@inheritdoc}
- */
- public function deleteItems(array $keys)
- {
- $ids = [];
-
- foreach ($keys as $key) {
- $ids[$key] = $this->getId($key);
- unset($this->deferred[$key]);
- }
-
- try {
- if ($this->doDelete($ids)) {
- return true;
- }
- } catch (\Exception $e) {
- }
-
- $ok = true;
-
- // When bulk-delete failed, retry each item individually
- foreach ($ids as $key => $id) {
- try {
- $e = null;
- if ($this->doDelete([$id])) {
- continue;
- }
- } catch (\Exception $e) {
- }
- $message = 'Failed to delete key "{key}"'.($e instanceof \Exception ? ': '.$e->getMessage() : '.');
- CacheItem::log($this->logger, $message, ['key' => $key, 'exception' => $e]);
- $ok = false;
- }
-
- return $ok;
- }
-
- /**
- * Enables/disables versioning of items.
- *
- * When versioning is enabled, clearing the cache is atomic and doesn't require listing existing keys to proceed,
- * but old keys may need garbage collection and extra round-trips to the back-end are required.
- *
- * Calling this method also clears the memoized namespace version and thus forces a resynchonization of it.
- *
- * @param bool $enable
- *
- * @return bool the previous state of versioning
- */
- public function enableVersioning($enable = true)
- {
- $wasEnabled = $this->versioningIsEnabled;
- $this->versioningIsEnabled = (bool) $enable;
- $this->namespaceVersion = '';
- $this->ids = [];
-
- return $wasEnabled;
- }
-
- /**
- * {@inheritdoc}
- */
- public function reset()
- {
- if ($this->deferred) {
- $this->commit();
- }
- $this->namespaceVersion = '';
- $this->ids = [];
- }
-
- /**
- * Like the native unserialize() function but throws an exception if anything goes wrong.
- *
- * @param string $value
- *
- * @return mixed
- *
- * @throws \Exception
- *
- * @deprecated since Symfony 4.2, use DefaultMarshaller instead.
- */
- protected static function unserialize($value)
- {
- @trigger_error(sprintf('The "%s::unserialize()" method is deprecated since Symfony 4.2, use DefaultMarshaller instead.', __CLASS__), E_USER_DEPRECATED);
-
- if ('b:0;' === $value) {
- return false;
- }
- $unserializeCallbackHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback');
- try {
- if (false !== $value = unserialize($value)) {
- return $value;
- }
- throw new \DomainException('Failed to unserialize cached value');
- } catch (\Error $e) {
- throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
- } finally {
- ini_set('unserialize_callback_func', $unserializeCallbackHandler);
- }
- }
-
- private function getId($key)
- {
- if ($this->versioningIsEnabled && '' === $this->namespaceVersion) {
- $this->ids = [];
- $this->namespaceVersion = '1/';
- try {
- foreach ($this->doFetch(['/'.$this->namespace]) as $v) {
- $this->namespaceVersion = $v;
- }
- if ('1:' === $this->namespaceVersion) {
- $this->namespaceVersion = substr_replace(base64_encode(pack('V', time())), ':', 5);
- $this->doSave(['@'.$this->namespace => $this->namespaceVersion], 0);
- }
- } catch (\Exception $e) {
- }
- }
-
- if (\is_string($key) && isset($this->ids[$key])) {
- return $this->namespace.$this->namespaceVersion.$this->ids[$key];
- }
- CacheItem::validateKey($key);
- $this->ids[$key] = $key;
-
- if (null === $this->maxIdLength) {
- return $this->namespace.$this->namespaceVersion.$key;
- }
- if (\strlen($id = $this->namespace.$this->namespaceVersion.$key) > $this->maxIdLength) {
- // Use MD5 to favor speed over security, which is not an issue here
- $this->ids[$key] = $id = substr_replace(base64_encode(hash('md5', $key, true)), ':', -(\strlen($this->namespaceVersion) + 2));
- $id = $this->namespace.$this->namespaceVersion.$id;
- }
-
- return $id;
- }
-
- /**
- * @internal
- */
- public static function handleUnserializeCallback($class)
- {
- throw new \DomainException('Class not found: '.$class);
- }
-}
diff --git a/src/Symfony/Component/Cache/Traits/ApcuTrait.php b/src/Symfony/Component/Cache/Traits/ApcuTrait.php
deleted file mode 100644
index c86b043ae1..0000000000
--- a/src/Symfony/Component/Cache/Traits/ApcuTrait.php
+++ /dev/null
@@ -1,121 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Cache\Traits;
-
-use Symfony\Component\Cache\CacheItem;
-use Symfony\Component\Cache\Exception\CacheException;
-
-/**
- * @author Nicolas Grekas
- *
- * @internal
- */
-trait ApcuTrait
-{
- public static function isSupported()
- {
- return \function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN);
- }
-
- private function init($namespace, $defaultLifetime, $version)
- {
- if (!static::isSupported()) {
- throw new CacheException('APCu is not enabled');
- }
- if ('cli' === \PHP_SAPI) {
- ini_set('apc.use_request_time', 0);
- }
- parent::__construct($namespace, $defaultLifetime);
-
- if (null !== $version) {
- CacheItem::validateKey($version);
-
- if (!apcu_exists($version.'@'.$namespace)) {
- $this->doClear($namespace);
- apcu_add($version.'@'.$namespace, null);
- }
- }
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFetch(array $ids)
- {
- $unserializeCallbackHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback');
- try {
- $values = [];
- foreach (apcu_fetch($ids, $ok) ?: [] as $k => $v) {
- if (null !== $v || $ok) {
- $values[$k] = $v;
- }
- }
-
- return $values;
- } catch (\Error $e) {
- throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
- } finally {
- ini_set('unserialize_callback_func', $unserializeCallbackHandler);
- }
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doHave($id)
- {
- return apcu_exists($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doClear($namespace)
- {
- return isset($namespace[0]) && class_exists('APCuIterator', false) && ('cli' !== \PHP_SAPI || filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN))
- ? apcu_delete(new \APCuIterator(sprintf('/^%s/', preg_quote($namespace, '/')), APC_ITER_KEY))
- : apcu_clear_cache();
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doDelete(array $ids)
- {
- foreach ($ids as $id) {
- apcu_delete($id);
- }
-
- return true;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave(array $values, $lifetime)
- {
- try {
- if (false === $failures = apcu_store($values, null, $lifetime)) {
- $failures = $values;
- }
-
- return array_keys($failures);
- } catch (\Throwable $e) {
- if (1 === \count($values)) {
- // Workaround https://github.com/krakjoe/apcu/issues/170
- apcu_delete(key($values));
- }
-
- throw $e;
- }
- }
-}
diff --git a/src/Symfony/Component/Cache/Traits/ArrayTrait.php b/src/Symfony/Component/Cache/Traits/ArrayTrait.php
deleted file mode 100644
index 8ae9cad59b..0000000000
--- a/src/Symfony/Component/Cache/Traits/ArrayTrait.php
+++ /dev/null
@@ -1,165 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Cache\Traits;
-
-use Psr\Log\LoggerAwareTrait;
-use Symfony\Component\Cache\CacheItem;
-
-/**
- * @author Nicolas Grekas
- *
- * @internal
- */
-trait ArrayTrait
-{
- use LoggerAwareTrait;
-
- private $storeSerialized;
- private $values = [];
- private $expiries = [];
-
- /**
- * Returns all cached values, with cache miss as null.
- *
- * @return array
- */
- public function getValues()
- {
- if (!$this->storeSerialized) {
- return $this->values;
- }
-
- $values = $this->values;
- foreach ($values as $k => $v) {
- if (null === $v || 'N;' === $v) {
- continue;
- }
- if (!\is_string($v) || !isset($v[2]) || ':' !== $v[1]) {
- $values[$k] = serialize($v);
- }
- }
-
- return $values;
- }
-
- /**
- * {@inheritdoc}
- */
- public function hasItem($key)
- {
- if (\is_string($key) && isset($this->expiries[$key]) && $this->expiries[$key] > microtime(true)) {
- return true;
- }
- CacheItem::validateKey($key);
-
- return isset($this->expiries[$key]) && !$this->deleteItem($key);
- }
-
- /**
- * {@inheritdoc}
- */
- public function clear()
- {
- $this->values = $this->expiries = [];
-
- return true;
- }
-
- /**
- * {@inheritdoc}
- */
- public function deleteItem($key)
- {
- if (!\is_string($key) || !isset($this->expiries[$key])) {
- CacheItem::validateKey($key);
- }
- unset($this->values[$key], $this->expiries[$key]);
-
- return true;
- }
-
- /**
- * {@inheritdoc}
- */
- public function reset()
- {
- $this->clear();
- }
-
- private function generateItems(array $keys, $now, $f)
- {
- foreach ($keys as $i => $key) {
- if (!$isHit = isset($this->expiries[$key]) && ($this->expiries[$key] > $now || !$this->deleteItem($key))) {
- $this->values[$key] = $value = null;
- } else {
- $value = $this->storeSerialized ? $this->unfreeze($key, $isHit) : $this->values[$key];
- }
- unset($keys[$i]);
-
- yield $key => $f($key, $value, $isHit);
- }
-
- foreach ($keys as $key) {
- yield $key => $f($key, null, false);
- }
- }
-
- private function freeze($value, $key)
- {
- if (null === $value) {
- return 'N;';
- }
- if (\is_string($value)) {
- // Serialize strings if they could be confused with serialized objects or arrays
- if ('N;' === $value || (isset($value[2]) && ':' === $value[1])) {
- return serialize($value);
- }
- } elseif (!\is_scalar($value)) {
- try {
- $serialized = serialize($value);
- } catch (\Exception $e) {
- $type = \is_object($value) ? \get_class($value) : \gettype($value);
- $message = sprintf('Failed to save key "{key}" of type %s: %s', $type, $e->getMessage());
- CacheItem::log($this->logger, $message, ['key' => substr($id, \strlen($this->namespace)), 'exception' => $e]);
-
- return;
- }
- // Keep value serialized if it contains any objects or any internal references
- if ('C' === $serialized[0] || 'O' === $serialized[0] || preg_match('/;[OCRr]:[1-9]/', $serialized)) {
- return $serialized;
- }
- }
-
- return $value;
- }
-
- private function unfreeze(string $key, bool &$isHit)
- {
- if ('N;' === $value = $this->values[$key]) {
- return null;
- }
- if (\is_string($value) && isset($value[2]) && ':' === $value[1]) {
- try {
- $value = unserialize($value);
- } catch (\Exception $e) {
- CacheItem::log($this->logger, 'Failed to unserialize key "{key}": '.$e->getMessage(), ['key' => $key, 'exception' => $e]);
- $value = false;
- }
- if (false === $value) {
- $this->values[$key] = $value = null;
- $isHit = false;
- }
- }
-
- return $value;
- }
-}
diff --git a/src/Symfony/Component/Cache/Traits/DoctrineTrait.php b/src/Symfony/Component/Cache/Traits/DoctrineTrait.php
deleted file mode 100644
index c87ecabafc..0000000000
--- a/src/Symfony/Component/Cache/Traits/DoctrineTrait.php
+++ /dev/null
@@ -1,98 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Cache\Traits;
-
-/**
- * @author Nicolas Grekas
- *
- * @internal
- */
-trait DoctrineTrait
-{
- private $provider;
-
- /**
- * {@inheritdoc}
- */
- public function reset()
- {
- parent::reset();
- $this->provider->setNamespace($this->provider->getNamespace());
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFetch(array $ids)
- {
- $unserializeCallbackHandler = ini_set('unserialize_callback_func', parent::class.'::handleUnserializeCallback');
- try {
- return $this->provider->fetchMultiple($ids);
- } catch (\Error $e) {
- $trace = $e->getTrace();
-
- if (isset($trace[0]['function']) && !isset($trace[0]['class'])) {
- switch ($trace[0]['function']) {
- case 'unserialize':
- case 'apcu_fetch':
- case 'apc_fetch':
- throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
- }
- }
-
- throw $e;
- } finally {
- ini_set('unserialize_callback_func', $unserializeCallbackHandler);
- }
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doHave($id)
- {
- return $this->provider->contains($id);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doClear($namespace)
- {
- $namespace = $this->provider->getNamespace();
-
- return isset($namespace[0])
- ? $this->provider->deleteAll()
- : $this->provider->flushAll();
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doDelete(array $ids)
- {
- $ok = true;
- foreach ($ids as $id) {
- $ok = $this->provider->delete($id) && $ok;
- }
-
- return $ok;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave(array $values, $lifetime)
- {
- return $this->provider->saveMultiple($values, $lifetime);
- }
-}
diff --git a/src/Symfony/Component/Cache/Traits/MemcachedTrait.php b/src/Symfony/Component/Cache/Traits/MemcachedTrait.php
deleted file mode 100644
index 9c52323943..0000000000
--- a/src/Symfony/Component/Cache/Traits/MemcachedTrait.php
+++ /dev/null
@@ -1,328 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Cache\Traits;
-
-use Symfony\Component\Cache\Exception\CacheException;
-use Symfony\Component\Cache\Exception\InvalidArgumentException;
-use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
-use Symfony\Component\Cache\Marshaller\MarshallerInterface;
-
-/**
- * @author Rob Frawley 2nd
- *
- * @internal
- */
-trait MemcachedTrait
-{
- private static $defaultClientOptions = [
- 'persistent_id' => null,
- 'username' => null,
- 'password' => null,
- 'serializer' => 'php',
- ];
-
- private $marshaller;
- private $client;
- private $lazyClient;
-
- public static function isSupported()
- {
- return \extension_loaded('memcached') && version_compare(phpversion('memcached'), '2.2.0', '>=');
- }
-
- private function init(\Memcached $client, $namespace, $defaultLifetime, ?MarshallerInterface $marshaller)
- {
- if (!static::isSupported()) {
- throw new CacheException('Memcached >= 2.2.0 is required');
- }
- if ('Memcached' === \get_class($client)) {
- $opt = $client->getOption(\Memcached::OPT_SERIALIZER);
- if (\Memcached::SERIALIZER_PHP !== $opt && \Memcached::SERIALIZER_IGBINARY !== $opt) {
- throw new CacheException('MemcachedAdapter: "serializer" option must be "php" or "igbinary".');
- }
- $this->maxIdLength -= \strlen($client->getOption(\Memcached::OPT_PREFIX_KEY));
- $this->client = $client;
- } else {
- $this->lazyClient = $client;
- }
-
- parent::__construct($namespace, $defaultLifetime);
- $this->enableVersioning();
- $this->marshaller = $marshaller ?? new DefaultMarshaller();
- }
-
- /**
- * Creates a Memcached instance.
- *
- * By default, the binary protocol, no block, and libketama compatible options are enabled.
- *
- * Examples for servers:
- * - 'memcached://user:pass@localhost?weight=33'
- * - [['localhost', 11211, 33]]
- *
- * @param array[]|string|string[] $servers An array of servers, a DSN, or an array of DSNs
- * @param array $options An array of options
- *
- * @return \Memcached
- *
- * @throws \ErrorException When invalid options or servers are provided
- */
- public static function createConnection($servers, array $options = [])
- {
- if (\is_string($servers)) {
- $servers = [$servers];
- } elseif (!\is_array($servers)) {
- throw new InvalidArgumentException(sprintf('MemcachedAdapter::createClient() expects array or string as first argument, %s given.', \gettype($servers)));
- }
- if (!static::isSupported()) {
- throw new CacheException('Memcached >= 2.2.0 is required');
- }
- set_error_handler(function ($type, $msg, $file, $line) { throw new \ErrorException($msg, 0, $type, $file, $line); });
- try {
- $options += static::$defaultClientOptions;
- $client = new \Memcached($options['persistent_id']);
- $username = $options['username'];
- $password = $options['password'];
-
- // parse any DSN in $servers
- foreach ($servers as $i => $dsn) {
- if (\is_array($dsn)) {
- continue;
- }
- if (0 !== strpos($dsn, 'memcached:')) {
- throw new InvalidArgumentException(sprintf('Invalid Memcached DSN: %s does not start with "memcached:"', $dsn));
- }
- $params = preg_replace_callback('#^memcached:(//)?(?:([^@]*+)@)?#', function ($m) use (&$username, &$password) {
- if (!empty($m[2])) {
- list($username, $password) = explode(':', $m[2], 2) + [1 => null];
- }
-
- return 'file:'.($m[1] ?? '');
- }, $dsn);
- if (false === $params = parse_url($params)) {
- throw new InvalidArgumentException(sprintf('Invalid Memcached DSN: %s', $dsn));
- }
- $query = $hosts = [];
- if (isset($params['query'])) {
- parse_str($params['query'], $query);
-
- if (isset($query['host'])) {
- if (!\is_array($hosts = $query['host'])) {
- throw new InvalidArgumentException(sprintf('Invalid Memcached DSN: %s', $dsn));
- }
- foreach ($hosts as $host => $weight) {
- if (false === $port = strrpos($host, ':')) {
- $hosts[$host] = [$host, 11211, (int) $weight];
- } else {
- $hosts[$host] = [substr($host, 0, $port), (int) substr($host, 1 + $port), (int) $weight];
- }
- }
- $hosts = array_values($hosts);
- unset($query['host']);
- }
- if ($hosts && !isset($params['host']) && !isset($params['path'])) {
- unset($servers[$i]);
- $servers = array_merge($servers, $hosts);
- continue;
- }
- }
- if (!isset($params['host']) && !isset($params['path'])) {
- throw new InvalidArgumentException(sprintf('Invalid Memcached DSN: %s', $dsn));
- }
- if (isset($params['path']) && preg_match('#/(\d+)$#', $params['path'], $m)) {
- $params['weight'] = $m[1];
- $params['path'] = substr($params['path'], 0, -\strlen($m[0]));
- }
- $params += [
- 'host' => isset($params['host']) ? $params['host'] : $params['path'],
- 'port' => isset($params['host']) ? 11211 : null,
- 'weight' => 0,
- ];
- if ($query) {
- $params += $query;
- $options = $query + $options;
- }
-
- $servers[$i] = [$params['host'], $params['port'], $params['weight']];
-
- if ($hosts) {
- $servers = array_merge($servers, $hosts);
- }
- }
-
- // set client's options
- unset($options['persistent_id'], $options['username'], $options['password'], $options['weight'], $options['lazy']);
- $options = array_change_key_case($options, CASE_UPPER);
- $client->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
- $client->setOption(\Memcached::OPT_NO_BLOCK, true);
- $client->setOption(\Memcached::OPT_TCP_NODELAY, true);
- if (!\array_key_exists('LIBKETAMA_COMPATIBLE', $options) && !\array_key_exists(\Memcached::OPT_LIBKETAMA_COMPATIBLE, $options)) {
- $client->setOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
- }
- foreach ($options as $name => $value) {
- if (\is_int($name)) {
- continue;
- }
- if ('HASH' === $name || 'SERIALIZER' === $name || 'DISTRIBUTION' === $name) {
- $value = \constant('Memcached::'.$name.'_'.strtoupper($value));
- }
- $opt = \constant('Memcached::OPT_'.$name);
-
- unset($options[$name]);
- $options[$opt] = $value;
- }
- $client->setOptions($options);
-
- // set client's servers, taking care of persistent connections
- if (!$client->isPristine()) {
- $oldServers = [];
- foreach ($client->getServerList() as $server) {
- $oldServers[] = [$server['host'], $server['port']];
- }
-
- $newServers = [];
- foreach ($servers as $server) {
- if (1 < \count($server)) {
- $server = array_values($server);
- unset($server[2]);
- $server[1] = (int) $server[1];
- }
- $newServers[] = $server;
- }
-
- if ($oldServers !== $newServers) {
- $client->resetServerList();
- $client->addServers($servers);
- }
- } else {
- $client->addServers($servers);
- }
-
- if (null !== $username || null !== $password) {
- if (!method_exists($client, 'setSaslAuthData')) {
- trigger_error('Missing SASL support: the memcached extension must be compiled with --enable-memcached-sasl.');
- }
- $client->setSaslAuthData($username, $password);
- }
-
- return $client;
- } finally {
- restore_error_handler();
- }
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave(array $values, $lifetime)
- {
- if (!$values = $this->marshaller->marshall($values, $failed)) {
- return $failed;
- }
-
- if ($lifetime && $lifetime > 30 * 86400) {
- $lifetime += time();
- }
-
- $encodedValues = [];
- foreach ($values as $key => $value) {
- $encodedValues[rawurlencode($key)] = $value;
- }
-
- return $this->checkResultCode($this->getClient()->setMulti($encodedValues, $lifetime)) ? $failed : false;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFetch(array $ids)
- {
- try {
- $encodedIds = array_map('rawurlencode', $ids);
-
- $encodedResult = $this->checkResultCode($this->getClient()->getMulti($encodedIds));
-
- $result = [];
- foreach ($encodedResult as $key => $value) {
- $result[rawurldecode($key)] = $this->marshaller->unmarshall($value);
- }
-
- return $result;
- } catch (\Error $e) {
- throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
- }
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doHave($id)
- {
- return false !== $this->getClient()->get(rawurlencode($id)) || $this->checkResultCode(\Memcached::RES_SUCCESS === $this->client->getResultCode());
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doDelete(array $ids)
- {
- $ok = true;
- $encodedIds = array_map('rawurlencode', $ids);
- foreach ($this->checkResultCode($this->getClient()->deleteMulti($encodedIds)) as $result) {
- if (\Memcached::RES_SUCCESS !== $result && \Memcached::RES_NOTFOUND !== $result) {
- $ok = false;
- }
- }
-
- return $ok;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doClear($namespace)
- {
- return '' === $namespace && $this->getClient()->flush();
- }
-
- private function checkResultCode($result)
- {
- $code = $this->client->getResultCode();
-
- if (\Memcached::RES_SUCCESS === $code || \Memcached::RES_NOTFOUND === $code) {
- return $result;
- }
-
- throw new CacheException(sprintf('MemcachedAdapter client error: %s.', strtolower($this->client->getResultMessage())));
- }
-
- /**
- * @return \Memcached
- */
- private function getClient()
- {
- if ($this->client) {
- return $this->client;
- }
-
- $opt = $this->lazyClient->getOption(\Memcached::OPT_SERIALIZER);
- if (\Memcached::SERIALIZER_PHP !== $opt && \Memcached::SERIALIZER_IGBINARY !== $opt) {
- throw new CacheException('MemcachedAdapter: "serializer" option must be "php" or "igbinary".');
- }
- if ('' !== $prefix = (string) $this->lazyClient->getOption(\Memcached::OPT_PREFIX_KEY)) {
- throw new CacheException(sprintf('MemcachedAdapter: "prefix_key" option must be empty when using proxified connections, "%s" given.', $prefix));
- }
-
- return $this->client = $this->lazyClient;
- }
-}
diff --git a/src/Symfony/Component/Cache/Traits/PdoTrait.php b/src/Symfony/Component/Cache/Traits/PdoTrait.php
deleted file mode 100644
index ec34e72fb5..0000000000
--- a/src/Symfony/Component/Cache/Traits/PdoTrait.php
+++ /dev/null
@@ -1,424 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Cache\Traits;
-
-use Doctrine\DBAL\Connection;
-use Doctrine\DBAL\DBALException;
-use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
-use Doctrine\DBAL\Exception\TableNotFoundException;
-use Doctrine\DBAL\Schema\Schema;
-use Symfony\Component\Cache\Exception\InvalidArgumentException;
-use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
-use Symfony\Component\Cache\Marshaller\MarshallerInterface;
-
-/**
- * @internal
- */
-trait PdoTrait
-{
- private $marshaller;
- private $conn;
- private $dsn;
- private $driver;
- private $serverVersion;
- private $table = 'cache_items';
- private $idCol = 'item_id';
- private $dataCol = 'item_data';
- private $lifetimeCol = 'item_lifetime';
- private $timeCol = 'item_time';
- private $username = '';
- private $password = '';
- private $connectionOptions = [];
- private $namespace;
-
- private function init($connOrDsn, $namespace, $defaultLifetime, array $options, ?MarshallerInterface $marshaller)
- {
- if (isset($namespace[0]) && preg_match('#[^-+.A-Za-z0-9]#', $namespace, $match)) {
- throw new InvalidArgumentException(sprintf('Namespace contains "%s" but only characters in [-+.A-Za-z0-9] are allowed.', $match[0]));
- }
-
- if ($connOrDsn instanceof \PDO) {
- if (\PDO::ERRMODE_EXCEPTION !== $connOrDsn->getAttribute(\PDO::ATTR_ERRMODE)) {
- throw new InvalidArgumentException(sprintf('"%s" requires PDO error mode attribute be set to throw Exceptions (i.e. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION))', __CLASS__));
- }
-
- $this->conn = $connOrDsn;
- } elseif ($connOrDsn instanceof Connection) {
- $this->conn = $connOrDsn;
- } elseif (\is_string($connOrDsn)) {
- $this->dsn = $connOrDsn;
- } else {
- throw new InvalidArgumentException(sprintf('"%s" requires PDO or Doctrine\DBAL\Connection instance or DSN string as first argument, "%s" given.', __CLASS__, \is_object($connOrDsn) ? \get_class($connOrDsn) : \gettype($connOrDsn)));
- }
-
- $this->table = isset($options['db_table']) ? $options['db_table'] : $this->table;
- $this->idCol = isset($options['db_id_col']) ? $options['db_id_col'] : $this->idCol;
- $this->dataCol = isset($options['db_data_col']) ? $options['db_data_col'] : $this->dataCol;
- $this->lifetimeCol = isset($options['db_lifetime_col']) ? $options['db_lifetime_col'] : $this->lifetimeCol;
- $this->timeCol = isset($options['db_time_col']) ? $options['db_time_col'] : $this->timeCol;
- $this->username = isset($options['db_username']) ? $options['db_username'] : $this->username;
- $this->password = isset($options['db_password']) ? $options['db_password'] : $this->password;
- $this->connectionOptions = isset($options['db_connection_options']) ? $options['db_connection_options'] : $this->connectionOptions;
- $this->namespace = $namespace;
- $this->marshaller = $marshaller ?? new DefaultMarshaller();
-
- parent::__construct($namespace, $defaultLifetime);
- }
-
- /**
- * Creates the table to store cache items which can be called once for setup.
- *
- * Cache ID are saved in a column of maximum length 255. Cache data is
- * saved in a BLOB.
- *
- * @throws \PDOException When the table already exists
- * @throws DBALException When the table already exists
- * @throws \DomainException When an unsupported PDO driver is used
- */
- public function createTable()
- {
- // connect if we are not yet
- $conn = $this->getConnection();
-
- if ($conn instanceof Connection) {
- $types = [
- 'mysql' => 'binary',
- 'sqlite' => 'text',
- 'pgsql' => 'string',
- 'oci' => 'string',
- 'sqlsrv' => 'string',
- ];
- if (!isset($types[$this->driver])) {
- throw new \DomainException(sprintf('Creating the cache table is currently not implemented for PDO driver "%s".', $this->driver));
- }
-
- $schema = new Schema();
- $table = $schema->createTable($this->table);
- $table->addColumn($this->idCol, $types[$this->driver], ['length' => 255]);
- $table->addColumn($this->dataCol, 'blob', ['length' => 16777215]);
- $table->addColumn($this->lifetimeCol, 'integer', ['unsigned' => true, 'notnull' => false]);
- $table->addColumn($this->timeCol, 'integer', ['unsigned' => true]);
- $table->setPrimaryKey([$this->idCol]);
-
- foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) {
- $conn->exec($sql);
- }
-
- return;
- }
-
- switch ($this->driver) {
- case 'mysql':
- // We use varbinary for the ID column because it prevents unwanted conversions:
- // - character set conversions between server and client
- // - trailing space removal
- // - case-insensitivity
- // - language processing like é == e
- $sql = "CREATE TABLE $this->table ($this->idCol VARBINARY(255) NOT NULL PRIMARY KEY, $this->dataCol MEDIUMBLOB NOT NULL, $this->lifetimeCol INTEGER UNSIGNED, $this->timeCol INTEGER UNSIGNED NOT NULL) COLLATE utf8_bin, ENGINE = InnoDB";
- break;
- case 'sqlite':
- $sql = "CREATE TABLE $this->table ($this->idCol TEXT NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
- break;
- case 'pgsql':
- $sql = "CREATE TABLE $this->table ($this->idCol VARCHAR(255) NOT NULL PRIMARY KEY, $this->dataCol BYTEA NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
- break;
- case 'oci':
- $sql = "CREATE TABLE $this->table ($this->idCol VARCHAR2(255) NOT NULL PRIMARY KEY, $this->dataCol BLOB NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
- break;
- case 'sqlsrv':
- $sql = "CREATE TABLE $this->table ($this->idCol VARCHAR(255) NOT NULL PRIMARY KEY, $this->dataCol VARBINARY(MAX) NOT NULL, $this->lifetimeCol INTEGER, $this->timeCol INTEGER NOT NULL)";
- break;
- default:
- throw new \DomainException(sprintf('Creating the cache table is currently not implemented for PDO driver "%s".', $this->driver));
- }
-
- $conn->exec($sql);
- }
-
- /**
- * {@inheritdoc}
- */
- public function prune()
- {
- $deleteSql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= :time";
-
- if ('' !== $this->namespace) {
- $deleteSql .= " AND $this->idCol LIKE :namespace";
- }
-
- try {
- $delete = $this->getConnection()->prepare($deleteSql);
- } catch (TableNotFoundException $e) {
- return true;
- }
- $delete->bindValue(':time', time(), \PDO::PARAM_INT);
-
- if ('' !== $this->namespace) {
- $delete->bindValue(':namespace', sprintf('%s%%', $this->namespace), \PDO::PARAM_STR);
- }
- try {
- return $delete->execute();
- } catch (TableNotFoundException $e) {
- return true;
- }
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doFetch(array $ids)
- {
- $now = time();
- $expired = [];
-
- $sql = str_pad('', (\count($ids) << 1) - 1, '?,');
- $sql = "SELECT $this->idCol, CASE WHEN $this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > ? THEN $this->dataCol ELSE NULL END FROM $this->table WHERE $this->idCol IN ($sql)";
- $stmt = $this->getConnection()->prepare($sql);
- $stmt->bindValue($i = 1, $now, \PDO::PARAM_INT);
- foreach ($ids as $id) {
- $stmt->bindValue(++$i, $id);
- }
- $stmt->execute();
-
- while ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
- if (null === $row[1]) {
- $expired[] = $row[0];
- } else {
- yield $row[0] => $this->marshaller->unmarshall(\is_resource($row[1]) ? stream_get_contents($row[1]) : $row[1]);
- }
- }
-
- if ($expired) {
- $sql = str_pad('', (\count($expired) << 1) - 1, '?,');
- $sql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= ? AND $this->idCol IN ($sql)";
- $stmt = $this->getConnection()->prepare($sql);
- $stmt->bindValue($i = 1, $now, \PDO::PARAM_INT);
- foreach ($expired as $id) {
- $stmt->bindValue(++$i, $id);
- }
- $stmt->execute();
- }
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doHave($id)
- {
- $sql = "SELECT 1 FROM $this->table WHERE $this->idCol = :id AND ($this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > :time)";
- $stmt = $this->getConnection()->prepare($sql);
-
- $stmt->bindValue(':id', $id);
- $stmt->bindValue(':time', time(), \PDO::PARAM_INT);
- $stmt->execute();
-
- return (bool) $stmt->fetchColumn();
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doClear($namespace)
- {
- $conn = $this->getConnection();
-
- if ('' === $namespace) {
- if ('sqlite' === $this->driver) {
- $sql = "DELETE FROM $this->table";
- } else {
- $sql = "TRUNCATE TABLE $this->table";
- }
- } else {
- $sql = "DELETE FROM $this->table WHERE $this->idCol LIKE '$namespace%'";
- }
-
- try {
- $conn->exec($sql);
- } catch (TableNotFoundException $e) {
- }
-
- return true;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doDelete(array $ids)
- {
- $sql = str_pad('', (\count($ids) << 1) - 1, '?,');
- $sql = "DELETE FROM $this->table WHERE $this->idCol IN ($sql)";
- try {
- $stmt = $this->getConnection()->prepare($sql);
- $stmt->execute(array_values($ids));
- } catch (TableNotFoundException $e) {
- }
-
- return true;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function doSave(array $values, $lifetime)
- {
- if (!$values = $this->marshaller->marshall($values, $failed)) {
- return $failed;
- }
-
- $conn = $this->getConnection();
- $driver = $this->driver;
- $insertSql = "INSERT INTO $this->table ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (:id, :data, :lifetime, :time)";
-
- switch (true) {
- case 'mysql' === $driver:
- $sql = $insertSql." ON DUPLICATE KEY UPDATE $this->dataCol = VALUES($this->dataCol), $this->lifetimeCol = VALUES($this->lifetimeCol), $this->timeCol = VALUES($this->timeCol)";
- break;
- case 'oci' === $driver:
- // DUAL is Oracle specific dummy table
- $sql = "MERGE INTO $this->table USING DUAL ON ($this->idCol = ?) ".
- "WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?) ".
- "WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?";
- break;
- case 'sqlsrv' === $driver && version_compare($this->getServerVersion(), '10', '>='):
- // MERGE is only available since SQL Server 2008 and must be terminated by semicolon
- // It also requires HOLDLOCK according to http://weblogs.sqlteam.com/dang/archive/2009/01/31/UPSERT-Race-Condition-With-MERGE.aspx
- $sql = "MERGE INTO $this->table WITH (HOLDLOCK) USING (SELECT 1 AS dummy) AS src ON ($this->idCol = ?) ".
- "WHEN NOT MATCHED THEN INSERT ($this->idCol, $this->dataCol, $this->lifetimeCol, $this->timeCol) VALUES (?, ?, ?, ?) ".
- "WHEN MATCHED THEN UPDATE SET $this->dataCol = ?, $this->lifetimeCol = ?, $this->timeCol = ?;";
- break;
- case 'sqlite' === $driver:
- $sql = 'INSERT OR REPLACE'.substr($insertSql, 6);
- break;
- case 'pgsql' === $driver && version_compare($this->getServerVersion(), '9.5', '>='):
- $sql = $insertSql." ON CONFLICT ($this->idCol) DO UPDATE SET ($this->dataCol, $this->lifetimeCol, $this->timeCol) = (EXCLUDED.$this->dataCol, EXCLUDED.$this->lifetimeCol, EXCLUDED.$this->timeCol)";
- break;
- default:
- $driver = null;
- $sql = "UPDATE $this->table SET $this->dataCol = :data, $this->lifetimeCol = :lifetime, $this->timeCol = :time WHERE $this->idCol = :id";
- break;
- }
-
- $now = time();
- $lifetime = $lifetime ?: null;
- try {
- $stmt = $conn->prepare($sql);
- } catch (TableNotFoundException $e) {
- if (!$conn->isTransactionActive() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
- $this->createTable();
- }
- $stmt = $conn->prepare($sql);
- }
-
- if ('sqlsrv' === $driver || 'oci' === $driver) {
- $stmt->bindParam(1, $id);
- $stmt->bindParam(2, $id);
- $stmt->bindParam(3, $data, \PDO::PARAM_LOB);
- $stmt->bindValue(4, $lifetime, \PDO::PARAM_INT);
- $stmt->bindValue(5, $now, \PDO::PARAM_INT);
- $stmt->bindParam(6, $data, \PDO::PARAM_LOB);
- $stmt->bindValue(7, $lifetime, \PDO::PARAM_INT);
- $stmt->bindValue(8, $now, \PDO::PARAM_INT);
- } else {
- $stmt->bindParam(':id', $id);
- $stmt->bindParam(':data', $data, \PDO::PARAM_LOB);
- $stmt->bindValue(':lifetime', $lifetime, \PDO::PARAM_INT);
- $stmt->bindValue(':time', $now, \PDO::PARAM_INT);
- }
- if (null === $driver) {
- $insertStmt = $conn->prepare($insertSql);
-
- $insertStmt->bindParam(':id', $id);
- $insertStmt->bindParam(':data', $data, \PDO::PARAM_LOB);
- $insertStmt->bindValue(':lifetime', $lifetime, \PDO::PARAM_INT);
- $insertStmt->bindValue(':time', $now, \PDO::PARAM_INT);
- }
-
- foreach ($values as $id => $data) {
- try {
- $stmt->execute();
- } catch (TableNotFoundException $e) {
- if (!$conn->isTransactionActive() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
- $this->createTable();
- }
- $stmt->execute();
- }
- if (null === $driver && !$stmt->rowCount()) {
- try {
- $insertStmt->execute();
- } catch (DBALException $e) {
- } catch (\PDOException $e) {
- // A concurrent write won, let it be
- }
- }
- }
-
- return $failed;
- }
-
- /**
- * @return \PDO|Connection
- */
- private function getConnection()
- {
- if (null === $this->conn) {
- $this->conn = new \PDO($this->dsn, $this->username, $this->password, $this->connectionOptions);
- $this->conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
- }
- if (null === $this->driver) {
- if ($this->conn instanceof \PDO) {
- $this->driver = $this->conn->getAttribute(\PDO::ATTR_DRIVER_NAME);
- } else {
- switch ($this->driver = $this->conn->getDriver()->getName()) {
- case 'mysqli':
- case 'pdo_mysql':
- case 'drizzle_pdo_mysql':
- $this->driver = 'mysql';
- break;
- case 'pdo_sqlite':
- $this->driver = 'sqlite';
- break;
- case 'pdo_pgsql':
- $this->driver = 'pgsql';
- break;
- case 'oci8':
- case 'pdo_oracle':
- $this->driver = 'oci';
- break;
- case 'pdo_sqlsrv':
- $this->driver = 'sqlsrv';
- break;
- }
- }
- }
-
- return $this->conn;
- }
-
- /**
- * @return string
- */
- private function getServerVersion()
- {
- if (null === $this->serverVersion) {
- $conn = $this->conn instanceof \PDO ? $this->conn : $this->conn->getWrappedConnection();
- if ($conn instanceof \PDO) {
- $this->serverVersion = $conn->getAttribute(\PDO::ATTR_SERVER_VERSION);
- } elseif ($conn instanceof ServerInfoAwareConnection) {
- $this->serverVersion = $conn->getServerVersion();
- } else {
- $this->serverVersion = '0';
- }
- }
-
- return $this->serverVersion;
- }
-}
diff --git a/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php b/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php
deleted file mode 100644
index 0bec18a07a..0000000000
--- a/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php
+++ /dev/null
@@ -1,152 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Cache\Traits;
-
-use Symfony\Component\Cache\CacheItem;
-use Symfony\Component\Cache\Exception\InvalidArgumentException;
-use Symfony\Component\VarExporter\VarExporter;
-
-/**
- * @author Titouan Galopin
- *
- * @internal
- */
-trait PhpArrayTrait
-{
- use ProxyTrait;
-
- private $file;
- private $keys;
- private $values;
-
- /**
- * Store an array of cached values.
- *
- * @param array $values The cached values
- */
- public function warmUp(array $values)
- {
- if (file_exists($this->file)) {
- if (!is_file($this->file)) {
- throw new InvalidArgumentException(sprintf('Cache path exists and is not a file: %s.', $this->file));
- }
-
- if (!is_writable($this->file)) {
- throw new InvalidArgumentException(sprintf('Cache file is not writable: %s.', $this->file));
- }
- } else {
- $directory = \dirname($this->file);
-
- if (!is_dir($directory) && !@mkdir($directory, 0777, true)) {
- throw new InvalidArgumentException(sprintf('Cache directory does not exist and cannot be created: %s.', $directory));
- }
-
- if (!is_writable($directory)) {
- throw new InvalidArgumentException(sprintf('Cache directory is not writable: %s.', $directory));
- }
- }
-
- $dumpedValues = '';
- $dumpedMap = [];
- $dump = <<<'EOF'
- $value) {
- CacheItem::validateKey(\is_int($key) ? (string) $key : $key);
- $isStaticValue = true;
-
- if (null === $value) {
- $value = "'N;'";
- } elseif (\is_object($value) || \is_array($value)) {
- try {
- $value = VarExporter::export($value, $isStaticValue);
- } catch (\Exception $e) {
- throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, \is_object($value) ? \get_class($value) : 'array'), 0, $e);
- }
- } elseif (\is_string($value)) {
- // Wrap "N;" in a closure to not confuse it with an encoded `null`
- if ('N;' === $value) {
- $isStaticValue = false;
- }
- $value = var_export($value, true);
- } elseif (!\is_scalar($value)) {
- throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, \gettype($value)));
- } else {
- $value = var_export($value, true);
- }
-
- if (!$isStaticValue) {
- $value = str_replace("\n", "\n ", $value);
- $value = "static function () {\n return {$value};\n}";
- }
- $hash = hash('md5', $value);
-
- if (null === $id = $dumpedMap[$hash] ?? null) {
- $id = $dumpedMap[$hash] = \count($dumpedMap);
- $dumpedValues .= "{$id} => {$value},\n";
- }
-
- $dump .= var_export($key, true)." => {$id},\n";
- }
-
- $dump .= "\n], [\n\n{$dumpedValues}\n]];\n";
-
- $tmpFile = uniqid($this->file, true);
-
- file_put_contents($tmpFile, $dump);
- @chmod($tmpFile, 0666 & ~umask());
- unset($serialized, $value, $dump);
-
- @rename($tmpFile, $this->file);
-
- $this->initialize();
- }
-
- /**
- * {@inheritdoc}
- */
- public function clear()
- {
- $this->keys = $this->values = [];
-
- $cleared = @unlink($this->file) || !file_exists($this->file);
-
- return $this->pool->clear() && $cleared;
- }
-
- /**
- * Load the cache file.
- */
- private function initialize()
- {
- if (!file_exists($this->file)) {
- $this->keys = $this->values = [];
-
- return;
- }
- $values = (include $this->file) ?: [[], []];
-
- if (2 !== \count($values) || !isset($values[0], $values[1])) {
- $this->keys = $this->values = [];
- } else {
- list($this->keys, $this->values) = $values;
- }
- }
-}
diff --git a/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php b/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php
deleted file mode 100644
index 37d25f87a9..0000000000
--- a/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php
+++ /dev/null
@@ -1,243 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Cache\Traits;
-
-use Symfony\Component\Cache\Exception\CacheException;
-use Symfony\Component\Cache\Exception\InvalidArgumentException;
-use Symfony\Component\VarExporter\VarExporter;
-
-/**
- * @author Piotr Stankowski
- * @author Rob Frawley 2nd