summaryrefslogtreecommitdiff
path: root/vendor/symfony/cache/Traits
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/cache/Traits')
-rw-r--r--vendor/symfony/cache/Traits/AbstractTrait.php34
-rw-r--r--vendor/symfony/cache/Traits/ApcuTrait.php4
-rw-r--r--vendor/symfony/cache/Traits/ArrayTrait.php10
-rw-r--r--vendor/symfony/cache/Traits/ContractsTrait.php2
-rw-r--r--vendor/symfony/cache/Traits/FilesystemTrait.php4
-rw-r--r--vendor/symfony/cache/Traits/MemcachedTrait.php34
-rw-r--r--vendor/symfony/cache/Traits/PdoTrait.php37
-rw-r--r--vendor/symfony/cache/Traits/PhpArrayTrait.php14
-rw-r--r--vendor/symfony/cache/Traits/PhpFilesTrait.php16
-rw-r--r--vendor/symfony/cache/Traits/RedisTrait.php64
10 files changed, 114 insertions, 105 deletions
diff --git a/vendor/symfony/cache/Traits/AbstractTrait.php b/vendor/symfony/cache/Traits/AbstractTrait.php
index 01351f11c9..2553ea75cb 100644
--- a/vendor/symfony/cache/Traits/AbstractTrait.php
+++ b/vendor/symfony/cache/Traits/AbstractTrait.php
@@ -26,8 +26,8 @@ trait AbstractTrait
private $namespace;
private $namespaceVersion = '';
private $versioningIsEnabled = false;
- private $deferred = array();
- private $ids = array();
+ private $deferred = [];
+ private $ids = [];
/**
* @var int|null The maximum length to enforce for identifiers or null when no limit applies
@@ -94,7 +94,7 @@ trait AbstractTrait
try {
return $this->doHave($id);
} catch (\Exception $e) {
- CacheItem::log($this->logger, 'Failed to check if key "{key}" is cached', array('key' => $key, 'exception' => $e));
+ CacheItem::log($this->logger, 'Failed to check if key "{key}" is cached', ['key' => $key, 'exception' => $e]);
return false;
}
@@ -105,24 +105,24 @@ trait AbstractTrait
*/
public function clear()
{
- $this->deferred = array();
+ $this->deferred = [];
if ($cleared = $this->versioningIsEnabled) {
$namespaceVersion = substr_replace(base64_encode(pack('V', mt_rand())), ':', 5);
try {
- $cleared = $this->doSave(array('/'.$this->namespace => $namespaceVersion), 0);
+ $cleared = $this->doSave(['/'.$this->namespace => $namespaceVersion], 0);
} catch (\Exception $e) {
$cleared = false;
}
- if ($cleared = true === $cleared || array() === $cleared) {
+ if ($cleared = true === $cleared || [] === $cleared) {
$this->namespaceVersion = $namespaceVersion;
- $this->ids = array();
+ $this->ids = [];
}
}
try {
return $this->doClear($this->namespace) || $cleared;
} catch (\Exception $e) {
- CacheItem::log($this->logger, 'Failed to clear the cache', array('exception' => $e));
+ CacheItem::log($this->logger, 'Failed to clear the cache', ['exception' => $e]);
return false;
}
@@ -133,7 +133,7 @@ trait AbstractTrait
*/
public function deleteItem($key)
{
- return $this->deleteItems(array($key));
+ return $this->deleteItems([$key]);
}
/**
@@ -141,7 +141,7 @@ trait AbstractTrait
*/
public function deleteItems(array $keys)
{
- $ids = array();
+ $ids = [];
foreach ($keys as $key) {
$ids[$key] = $this->getId($key);
@@ -161,12 +161,12 @@ trait AbstractTrait
foreach ($ids as $key => $id) {
try {
$e = null;
- if ($this->doDelete(array($id))) {
+ if ($this->doDelete([$id])) {
continue;
}
} catch (\Exception $e) {
}
- CacheItem::log($this->logger, 'Failed to delete key "{key}"', array('key' => $key, 'exception' => $e));
+ CacheItem::log($this->logger, 'Failed to delete key "{key}"', ['key' => $key, 'exception' => $e]);
$ok = false;
}
@@ -190,7 +190,7 @@ trait AbstractTrait
$wasEnabled = $this->versioningIsEnabled;
$this->versioningIsEnabled = (bool) $enable;
$this->namespaceVersion = '';
- $this->ids = array();
+ $this->ids = [];
return $wasEnabled;
}
@@ -204,7 +204,7 @@ trait AbstractTrait
$this->commit();
}
$this->namespaceVersion = '';
- $this->ids = array();
+ $this->ids = [];
}
/**
@@ -241,15 +241,15 @@ trait AbstractTrait
private function getId($key)
{
if ($this->versioningIsEnabled && '' === $this->namespaceVersion) {
- $this->ids = array();
+ $this->ids = [];
$this->namespaceVersion = '1/';
try {
- foreach ($this->doFetch(array('/'.$this->namespace)) as $v) {
+ 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(array('@'.$this->namespace => $this->namespaceVersion), 0);
+ $this->doSave(['@'.$this->namespace => $this->namespaceVersion], 0);
}
} catch (\Exception $e) {
}
diff --git a/vendor/symfony/cache/Traits/ApcuTrait.php b/vendor/symfony/cache/Traits/ApcuTrait.php
index a93fc812a1..c86b043ae1 100644
--- a/vendor/symfony/cache/Traits/ApcuTrait.php
+++ b/vendor/symfony/cache/Traits/ApcuTrait.php
@@ -53,8 +53,8 @@ trait ApcuTrait
{
$unserializeCallbackHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback');
try {
- $values = array();
- foreach (apcu_fetch($ids, $ok) ?: array() as $k => $v) {
+ $values = [];
+ foreach (apcu_fetch($ids, $ok) ?: [] as $k => $v) {
if (null !== $v || $ok) {
$values[$k] = $v;
}
diff --git a/vendor/symfony/cache/Traits/ArrayTrait.php b/vendor/symfony/cache/Traits/ArrayTrait.php
index 8268e40db4..e585c3d48c 100644
--- a/vendor/symfony/cache/Traits/ArrayTrait.php
+++ b/vendor/symfony/cache/Traits/ArrayTrait.php
@@ -24,8 +24,8 @@ trait ArrayTrait
use LoggerAwareTrait;
private $storeSerialized;
- private $values = array();
- private $expiries = array();
+ private $values = [];
+ private $expiries = [];
/**
* Returns all cached values, with cache miss as null.
@@ -69,7 +69,7 @@ trait ArrayTrait
*/
public function clear()
{
- $this->values = $this->expiries = array();
+ $this->values = $this->expiries = [];
return true;
}
@@ -128,7 +128,7 @@ trait ArrayTrait
$serialized = serialize($value);
} catch (\Exception $e) {
$type = \is_object($value) ? \get_class($value) : \gettype($value);
- CacheItem::log($this->logger, 'Failed to save key "{key}" ({type})', array('key' => $key, 'type' => $type, 'exception' => $e));
+ CacheItem::log($this->logger, 'Failed to save key "{key}" ({type})', ['key' => $key, 'type' => $type, 'exception' => $e]);
return;
}
@@ -150,7 +150,7 @@ trait ArrayTrait
try {
$value = unserialize($value);
} catch (\Exception $e) {
- CacheItem::log($this->logger, 'Failed to unserialize key "{key}"', array('key' => $key, 'exception' => $e));
+ CacheItem::log($this->logger, 'Failed to unserialize key "{key}"', ['key' => $key, 'exception' => $e]);
$value = false;
}
if (false === $value) {
diff --git a/vendor/symfony/cache/Traits/ContractsTrait.php b/vendor/symfony/cache/Traits/ContractsTrait.php
index f755e65fc3..8b1eb5a244 100644
--- a/vendor/symfony/cache/Traits/ContractsTrait.php
+++ b/vendor/symfony/cache/Traits/ContractsTrait.php
@@ -30,7 +30,7 @@ trait ContractsTrait
doGet as private contractsGet;
}
- private $callbackWrapper = array(LockRegistry::class, 'compute');
+ private $callbackWrapper = [LockRegistry::class, 'compute'];
/**
* Wraps the callback passed to ->get() in a callable.
diff --git a/vendor/symfony/cache/Traits/FilesystemTrait.php b/vendor/symfony/cache/Traits/FilesystemTrait.php
index 52dcf985dd..9c444f9b04 100644
--- a/vendor/symfony/cache/Traits/FilesystemTrait.php
+++ b/vendor/symfony/cache/Traits/FilesystemTrait.php
@@ -54,7 +54,7 @@ trait FilesystemTrait
*/
protected function doFetch(array $ids)
{
- $values = array();
+ $values = [];
$now = time();
foreach ($ids as $id) {
@@ -85,7 +85,7 @@ trait FilesystemTrait
{
$file = $this->getFile($id);
- return file_exists($file) && (@filemtime($file) > time() || $this->doFetch(array($id)));
+ return file_exists($file) && (@filemtime($file) > time() || $this->doFetch([$id]));
}
/**
diff --git a/vendor/symfony/cache/Traits/MemcachedTrait.php b/vendor/symfony/cache/Traits/MemcachedTrait.php
index 1e1718a412..b83d695937 100644
--- a/vendor/symfony/cache/Traits/MemcachedTrait.php
+++ b/vendor/symfony/cache/Traits/MemcachedTrait.php
@@ -24,12 +24,12 @@ use Symfony\Component\Cache\Marshaller\MarshallerInterface;
*/
trait MemcachedTrait
{
- private static $defaultClientOptions = array(
+ private static $defaultClientOptions = [
'persistent_id' => null,
'username' => null,
'password' => null,
'serializer' => 'php',
- );
+ ];
private $marshaller;
private $client;
@@ -68,7 +68,7 @@ trait MemcachedTrait
*
* Examples for servers:
* - 'memcached://user:pass@localhost?weight=33'
- * - array(array('localhost', 11211, 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
@@ -77,10 +77,10 @@ trait MemcachedTrait
*
* @throws \ErrorException When invalid options or servers are provided
*/
- public static function createConnection($servers, array $options = array())
+ public static function createConnection($servers, array $options = [])
{
if (\is_string($servers)) {
- $servers = array($servers);
+ $servers = [$servers];
} elseif (!\is_array($servers)) {
throw new InvalidArgumentException(sprintf('MemcachedAdapter::createClient() expects array or string as first argument, %s given.', \gettype($servers)));
}
@@ -104,7 +104,7 @@ trait MemcachedTrait
}
$params = preg_replace_callback('#^memcached:(//)?(?:([^@]*+)@)?#', function ($m) use (&$username, &$password) {
if (!empty($m[2])) {
- list($username, $password) = explode(':', $m[2], 2) + array(1 => null);
+ list($username, $password) = explode(':', $m[2], 2) + [1 => null];
}
return 'file:'.($m[1] ?? '');
@@ -112,7 +112,7 @@ trait MemcachedTrait
if (false === $params = parse_url($params)) {
throw new InvalidArgumentException(sprintf('Invalid Memcached DSN: %s', $dsn));
}
- $query = $hosts = array();
+ $query = $hosts = [];
if (isset($params['query'])) {
parse_str($params['query'], $query);
@@ -122,9 +122,9 @@ trait MemcachedTrait
}
foreach ($hosts as $host => $weight) {
if (false === $port = strrpos($host, ':')) {
- $hosts[$host] = array($host, 11211, (int) $weight);
+ $hosts[$host] = [$host, 11211, (int) $weight];
} else {
- $hosts[$host] = array(substr($host, 0, $port), (int) substr($host, 1 + $port), (int) $weight);
+ $hosts[$host] = [substr($host, 0, $port), (int) substr($host, 1 + $port), (int) $weight];
}
}
$hosts = array_values($hosts);
@@ -143,17 +143,17 @@ trait MemcachedTrait
$params['weight'] = $m[1];
$params['path'] = substr($params['path'], 0, -\strlen($m[0]));
}
- $params += array(
+ $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] = array($params['host'], $params['port'], $params['weight']);
+ $servers[$i] = [$params['host'], $params['port'], $params['weight']];
if ($hosts) {
$servers = array_merge($servers, $hosts);
@@ -185,12 +185,12 @@ trait MemcachedTrait
// set client's servers, taking care of persistent connections
if (!$client->isPristine()) {
- $oldServers = array();
+ $oldServers = [];
foreach ($client->getServerList() as $server) {
- $oldServers[] = array($server['host'], $server['port']);
+ $oldServers[] = [$server['host'], $server['port']];
}
- $newServers = array();
+ $newServers = [];
foreach ($servers as $server) {
if (1 < \count($server)) {
$server = array_values($server);
@@ -234,7 +234,7 @@ trait MemcachedTrait
$lifetime += time();
}
- $encodedValues = array();
+ $encodedValues = [];
foreach ($values as $key => $value) {
$encodedValues[rawurlencode($key)] = $value;
}
@@ -252,7 +252,7 @@ trait MemcachedTrait
$encodedResult = $this->checkResultCode($this->getClient()->getMulti($encodedIds));
- $result = array();
+ $result = [];
foreach ($encodedResult as $key => $value) {
$result[rawurldecode($key)] = $this->marshaller->unmarshall($value);
}
diff --git a/vendor/symfony/cache/Traits/PdoTrait.php b/vendor/symfony/cache/Traits/PdoTrait.php
index ea4feee4ac..ec34e72fb5 100644
--- a/vendor/symfony/cache/Traits/PdoTrait.php
+++ b/vendor/symfony/cache/Traits/PdoTrait.php
@@ -37,7 +37,7 @@ trait PdoTrait
private $timeCol = 'item_time';
private $username = '';
private $password = '';
- private $connectionOptions = array();
+ private $connectionOptions = [];
private $namespace;
private function init($connOrDsn, $namespace, $defaultLifetime, array $options, ?MarshallerInterface $marshaller)
@@ -90,24 +90,24 @@ trait PdoTrait
$conn = $this->getConnection();
if ($conn instanceof Connection) {
- $types = array(
+ $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], array('length' => 255));
- $table->addColumn($this->dataCol, 'blob', array('length' => 16777215));
- $table->addColumn($this->lifetimeCol, 'integer', array('unsigned' => true, 'notnull' => false));
- $table->addColumn($this->timeCol, 'integer', array('unsigned' => true));
- $table->setPrimaryKey(array($this->idCol));
+ $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);
@@ -165,8 +165,11 @@ trait PdoTrait
if ('' !== $this->namespace) {
$delete->bindValue(':namespace', sprintf('%s%%', $this->namespace), \PDO::PARAM_STR);
}
-
- return $delete->execute();
+ try {
+ return $delete->execute();
+ } catch (TableNotFoundException $e) {
+ return true;
+ }
}
/**
@@ -175,7 +178,7 @@ trait PdoTrait
protected function doFetch(array $ids)
{
$now = time();
- $expired = array();
+ $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)";
@@ -309,7 +312,7 @@ trait PdoTrait
try {
$stmt = $conn->prepare($sql);
} catch (TableNotFoundException $e) {
- if (!$conn->isTransactionActive() || \in_array($this->driver, array('pgsql', 'sqlite', 'sqlsrv'), true)) {
+ if (!$conn->isTransactionActive() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
$this->createTable();
}
$stmt = $conn->prepare($sql);
@@ -340,8 +343,14 @@ trait PdoTrait
}
foreach ($values as $id => $data) {
- $stmt->execute();
-
+ 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();
diff --git a/vendor/symfony/cache/Traits/PhpArrayTrait.php b/vendor/symfony/cache/Traits/PhpArrayTrait.php
index 587da5a498..0bec18a07a 100644
--- a/vendor/symfony/cache/Traits/PhpArrayTrait.php
+++ b/vendor/symfony/cache/Traits/PhpArrayTrait.php
@@ -57,13 +57,13 @@ trait PhpArrayTrait
}
$dumpedValues = '';
- $dumpedMap = array();
+ $dumpedMap = [];
$dump = <<<'EOF'
<?php
// This file has been auto-generated by the Symfony Cache Component.
-return array(array(
+return [[
EOF;
@@ -106,7 +106,7 @@ EOF;
$dump .= var_export($key, true)." => {$id},\n";
}
- $dump .= "\n), array(\n\n{$dumpedValues}\n));\n";
+ $dump .= "\n], [\n\n{$dumpedValues}\n]];\n";
$tmpFile = uniqid($this->file, true);
@@ -124,7 +124,7 @@ EOF;
*/
public function clear()
{
- $this->keys = $this->values = array();
+ $this->keys = $this->values = [];
$cleared = @unlink($this->file) || !file_exists($this->file);
@@ -137,14 +137,14 @@ EOF;
private function initialize()
{
if (!file_exists($this->file)) {
- $this->keys = $this->values = array();
+ $this->keys = $this->values = [];
return;
}
- $values = (include $this->file) ?: array(array(), array());
+ $values = (include $this->file) ?: [[], []];
if (2 !== \count($values) || !isset($values[0], $values[1])) {
- $this->keys = $this->values = array();
+ $this->keys = $this->values = [];
} else {
list($this->keys, $this->values) = $values;
}
diff --git a/vendor/symfony/cache/Traits/PhpFilesTrait.php b/vendor/symfony/cache/Traits/PhpFilesTrait.php
index 636ad3d99b..b57addb54f 100644
--- a/vendor/symfony/cache/Traits/PhpFilesTrait.php
+++ b/vendor/symfony/cache/Traits/PhpFilesTrait.php
@@ -31,8 +31,8 @@ trait PhpFilesTrait
private $includeHandler;
private $appendOnly;
- private $values = array();
- private $files = array();
+ private $values = [];
+ private $files = [];
private static $startTime;
@@ -78,13 +78,13 @@ trait PhpFilesTrait
{
if ($this->appendOnly) {
$now = 0;
- $missingIds = array();
+ $missingIds = [];
} else {
$now = time();
$missingIds = $ids;
- $ids = array();
+ $ids = [];
}
- $values = array();
+ $values = [];
begin:
foreach ($ids as $id) {
@@ -124,7 +124,7 @@ trait PhpFilesTrait
}
$ids = $missingIds;
- $missingIds = array();
+ $missingIds = [];
goto begin;
}
@@ -195,7 +195,7 @@ trait PhpFilesTrait
$file = $this->files[$key] = $this->getFile($key, true);
// Since OPcache only compiles files older than the script execution start, set the file's mtime in the past
- $ok = $this->write($file, "<?php return array({$expiry}, {$value});\n", self::$startTime - 10) && $ok;
+ $ok = $this->write($file, "<?php return [{$expiry}, {$value}];\n", self::$startTime - 10) && $ok;
if ($allowCompile) {
@opcache_invalidate($file, true);
@@ -215,7 +215,7 @@ trait PhpFilesTrait
*/
protected function doClear($namespace)
{
- $this->values = array();
+ $this->values = [];
return $this->doCommonClear($namespace);
}
diff --git a/vendor/symfony/cache/Traits/RedisTrait.php b/vendor/symfony/cache/Traits/RedisTrait.php
index a7224d216f..0276c4fb6d 100644
--- a/vendor/symfony/cache/Traits/RedisTrait.php
+++ b/vendor/symfony/cache/Traits/RedisTrait.php
@@ -27,7 +27,7 @@ use Symfony\Component\Cache\Marshaller\MarshallerInterface;
*/
trait RedisTrait
{
- private static $defaultConnectionOptions = array(
+ private static $defaultConnectionOptions = [
'class' => null,
'persistent' => 0,
'persistent_id' => null,
@@ -40,7 +40,7 @@ trait RedisTrait
'redis_cluster' => false,
'dbindex' => 0,
'failover' => 'none',
- );
+ ];
private $redis;
private $marshaller;
@@ -78,7 +78,7 @@ trait RedisTrait
*
* @return \Redis|\RedisCluster|\Predis\Client According to the "class" option
*/
- public static function createConnection($dsn, array $options = array())
+ public static function createConnection($dsn, array $options = [])
{
if (0 !== strpos($dsn, 'redis:')) {
throw new InvalidArgumentException(sprintf('Invalid Redis DSN: %s does not start with "redis:".', $dsn));
@@ -100,7 +100,7 @@ trait RedisTrait
throw new InvalidArgumentException(sprintf('Invalid Redis DSN: %s', $dsn));
}
- $query = $hosts = array();
+ $query = $hosts = [];
if (isset($params['query'])) {
parse_str($params['query'], $query);
@@ -114,11 +114,11 @@ trait RedisTrait
parse_str($parameters, $parameters);
}
if (false === $i = strrpos($host, ':')) {
- $hosts[$host] = array('scheme' => 'tcp', 'host' => $host, 'port' => 6379) + $parameters;
+ $hosts[$host] = ['scheme' => 'tcp', 'host' => $host, 'port' => 6379] + $parameters;
} elseif ($port = (int) substr($host, 1 + $i)) {
- $hosts[$host] = array('scheme' => 'tcp', 'host' => substr($host, 0, $i), 'port' => $port) + $parameters;
+ $hosts[$host] = ['scheme' => 'tcp', 'host' => substr($host, 0, $i), 'port' => $port] + $parameters;
} else {
- $hosts[$host] = array('scheme' => 'unix', 'path' => substr($host, 0, $i)) + $parameters;
+ $hosts[$host] = ['scheme' => 'unix', 'path' => substr($host, 0, $i)] + $parameters;
}
}
$hosts = array_values($hosts);
@@ -132,9 +132,9 @@ trait RedisTrait
}
if (isset($params['host'])) {
- array_unshift($hosts, array('scheme' => 'tcp', 'host' => $params['host'], 'port' => $params['port'] ?? 6379));
+ array_unshift($hosts, ['scheme' => 'tcp', 'host' => $params['host'], 'port' => $params['port'] ?? 6379]);
} else {
- array_unshift($hosts, array('scheme' => 'unix', 'path' => $params['path']));
+ array_unshift($hosts, ['scheme' => 'unix', 'path' => $params['path']]);
}
}
@@ -156,7 +156,7 @@ trait RedisTrait
$initializer = function ($redis) use ($connect, $params, $dsn, $auth, $hosts) {
try {
- @$redis->{$connect}($hosts[0]['host'], $hosts[0]['port'], $params['timeout'], (string) $params['persistent_id'], $params['retry_interval']);
+ @$redis->{$connect}($hosts[0]['host'] ?? $hosts[0]['path'], $hosts[0]['port'] ?? null, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval']);
} catch (\RedisException $e) {
throw new InvalidArgumentException(sprintf('Redis connection failed (%s): %s', $e->getMessage(), $dsn));
}
@@ -243,13 +243,13 @@ trait RedisTrait
if ($params['redis_cluster']) {
$params['cluster'] = 'redis';
}
- $params += array('parameters' => array());
- $params['parameters'] += array(
+ $params += ['parameters' => []];
+ $params['parameters'] += [
'persistent' => $params['persistent'],
'timeout' => $params['timeout'],
'read_write_timeout' => $params['read_timeout'],
'tcp_nodelay' => true,
- );
+ ];
if ($params['dbindex']) {
$params['parameters']['database'] = $params['dbindex'];
}
@@ -258,9 +258,9 @@ trait RedisTrait
}
if (1 === \count($hosts) && !$params['redis_cluster']) {
$hosts = $hosts[0];
- } elseif (\in_array($params['failover'], array('slaves', 'distribute'), true) && !isset($params['replication'])) {
+ } elseif (\in_array($params['failover'], ['slaves', 'distribute'], true) && !isset($params['replication'])) {
$params['replication'] = true;
- $hosts[0] += array('alias' => 'master');
+ $hosts[0] += ['alias' => 'master'];
}
$redis = new $class($hosts, array_diff_key($params, self::$defaultConnectionOptions));
@@ -279,15 +279,15 @@ trait RedisTrait
protected function doFetch(array $ids)
{
if (!$ids) {
- return array();
+ return [];
}
- $result = array();
+ $result = [];
if ($this->redis instanceof \Predis\Client) {
$values = $this->pipeline(function () use ($ids) {
foreach ($ids as $id) {
- yield 'get' => array($id);
+ yield 'get' => [$id];
}
});
} else {
@@ -317,26 +317,26 @@ trait RedisTrait
protected function doClear($namespace)
{
$cleared = true;
- $hosts = array($this->redis);
- $evalArgs = array(array($namespace), 0);
+ $hosts = [$this->redis];
+ $evalArgs = [[$namespace], 0];
if ($this->redis instanceof \Predis\Client) {
- $evalArgs = array(0, $namespace);
+ $evalArgs = [0, $namespace];
$connection = $this->redis->getConnection();
if ($connection instanceof ClusterInterface && $connection instanceof \Traversable) {
- $hosts = array();
+ $hosts = [];
foreach ($connection as $c) {
$hosts[] = new \Predis\Client($c);
}
}
} elseif ($this->redis instanceof \RedisArray) {
- $hosts = array();
+ $hosts = [];
foreach ($this->redis->_hosts() as $host) {
$hosts[] = $this->redis->_instance($host);
}
} elseif ($this->redis instanceof RedisClusterProxy || $this->redis instanceof \RedisCluster) {
- $hosts = array();
+ $hosts = [];
foreach ($this->redis->_masters() as $host) {
$hosts[] = $h = new \Redis();
$h->connect($host[0], $host[1]);
@@ -388,7 +388,7 @@ trait RedisTrait
if ($this->redis instanceof \Predis\Client) {
$this->pipeline(function () use ($ids) {
foreach ($ids as $id) {
- yield 'del' => array($id);
+ yield 'del' => [$id];
}
})->rewind();
} else {
@@ -410,9 +410,9 @@ trait RedisTrait
$results = $this->pipeline(function () use ($values, $lifetime) {
foreach ($values as $id => $value) {
if (0 >= $lifetime) {
- yield 'set' => array($id, $value);
+ yield 'set' => [$id, $value];
} else {
- yield 'setEx' => array($id, $lifetime, $value);
+ yield 'setEx' => [$id, $lifetime, $value];
}
}
});
@@ -427,13 +427,13 @@ trait RedisTrait
private function pipeline(\Closure $generator)
{
- $ids = array();
+ $ids = [];
if ($this->redis instanceof RedisClusterProxy || $this->redis instanceof \RedisCluster || ($this->redis instanceof \Predis\Client && $this->redis->getConnection() instanceof RedisCluster)) {
// phpredis & predis don't support pipelining with RedisCluster
// see https://github.com/phpredis/phpredis/blob/develop/cluster.markdown#pipelining
// see https://github.com/nrk/predis/issues/267#issuecomment-123781423
- $results = array();
+ $results = [];
foreach ($generator() as $command => $args) {
$results[] = $this->redis->{$command}(...$args);
$ids[] = $args[0];
@@ -446,14 +446,14 @@ trait RedisTrait
}
});
} elseif ($this->redis instanceof \RedisArray) {
- $connections = $results = $ids = array();
+ $connections = $results = $ids = [];
foreach ($generator() as $command => $args) {
if (!isset($connections[$h = $this->redis->_target($args[0])])) {
- $connections[$h] = array($this->redis->_instance($h), -1);
+ $connections[$h] = [$this->redis->_instance($h), -1];
$connections[$h][0]->multi(\Redis::PIPELINE);
}
$connections[$h][0]->{$command}(...$args);
- $results[] = array($h, ++$connections[$h][1]);
+ $results[] = [$h, ++$connections[$h][1]];
$ids[] = $args[0];
}
foreach ($connections as $h => $c) {