Merge branch '4.4' into 5.2
* 4.4: [Cache] backport type fixes
This commit is contained in:
commit
d008bd6878
2
.github/workflows/integration-tests.yml
vendored
2
.github/workflows/integration-tests.yml
vendored
@ -123,7 +123,7 @@ jobs:
|
||||
with:
|
||||
coverage: "none"
|
||||
extensions: "json,couchbase,memcached,mongodb,redis,rdkafka,xsl,ldap"
|
||||
ini-values: "memory_limit=-1"
|
||||
ini-values: date.timezone=Europe/Paris,memory_limit=-1,default_socket_timeout=10,session.gc_probability=0,apc.enable_cli=1,zend.assertions=1
|
||||
php-version: "${{ matrix.php }}"
|
||||
tools: pecl
|
||||
|
||||
|
2
.github/workflows/unit-tests.yml
vendored
2
.github/workflows/unit-tests.yml
vendored
@ -46,7 +46,7 @@ jobs:
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
coverage: "none"
|
||||
ini-values: date.timezone=Europe/Paris,memory_limit=-1,default_socket_timeout=10,session.gc_probability=0,apc.enable_cli=1
|
||||
ini-values: date.timezone=Europe/Paris,memory_limit=-1,default_socket_timeout=10,session.gc_probability=0,apc.enable_cli=1,zend.assertions=1
|
||||
php-version: "${{ matrix.php }}"
|
||||
extensions: "${{ env.extensions }}"
|
||||
tools: flex
|
||||
|
@ -312,7 +312,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
|
||||
$this->clear();
|
||||
}
|
||||
|
||||
private function generateItems(array $keys, $now, $f)
|
||||
private function generateItems(array $keys, float $now, \Closure $f)
|
||||
{
|
||||
foreach ($keys as $i => $key) {
|
||||
if (!$isHit = isset($this->expiries[$key]) && ($this->expiries[$key] > $now || !$this->deleteItem($key))) {
|
||||
@ -342,7 +342,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
|
||||
}
|
||||
}
|
||||
|
||||
private function freeze($value, $key)
|
||||
private function freeze($value, string $key)
|
||||
{
|
||||
if (null === $value) {
|
||||
return 'N;';
|
||||
|
@ -182,7 +182,7 @@ class CouchbaseBucketAdapter extends AbstractAdapter
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doHave($id): bool
|
||||
protected function doHave(string $id): bool
|
||||
{
|
||||
return false !== $this->bucket->get($id);
|
||||
}
|
||||
@ -190,7 +190,7 @@ class CouchbaseBucketAdapter extends AbstractAdapter
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doClear($namespace): bool
|
||||
protected function doClear(string $namespace): bool
|
||||
{
|
||||
if ('' === $namespace) {
|
||||
$this->bucket->manager()->flush();
|
||||
@ -221,7 +221,7 @@ class CouchbaseBucketAdapter extends AbstractAdapter
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doSave(array $values, $lifetime)
|
||||
protected function doSave(array $values, int $lifetime)
|
||||
{
|
||||
if (!$values = $this->marshaller->marshall($values, $failed)) {
|
||||
return $failed;
|
||||
|
@ -292,7 +292,7 @@ class PhpFilesAdapter extends AbstractAdapter implements PruneableInterface
|
||||
return $this->doCommonDelete($ids);
|
||||
}
|
||||
|
||||
protected function doUnlink($file)
|
||||
protected function doUnlink(string $file)
|
||||
{
|
||||
unset(self::$valuesCache[$file]);
|
||||
|
||||
@ -323,7 +323,7 @@ class LazyValue
|
||||
{
|
||||
public $file;
|
||||
|
||||
public function __construct($file)
|
||||
public function __construct(string $file)
|
||||
{
|
||||
$this->file = $file;
|
||||
}
|
||||
|
@ -12,6 +12,8 @@
|
||||
namespace Symfony\Component\Cache\Adapter;
|
||||
|
||||
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
|
||||
use Symfony\Component\Cache\Traits\RedisClusterProxy;
|
||||
use Symfony\Component\Cache\Traits\RedisProxy;
|
||||
use Symfony\Component\Cache\Traits\RedisTrait;
|
||||
|
||||
class RedisAdapter extends AbstractAdapter
|
||||
@ -19,12 +21,12 @@ class RedisAdapter extends AbstractAdapter
|
||||
use RedisTrait;
|
||||
|
||||
/**
|
||||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient The redis client
|
||||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis The redis client
|
||||
* @param string $namespace The default namespace
|
||||
* @param int $defaultLifetime The default lifetime
|
||||
*/
|
||||
public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
|
||||
public function __construct($redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
|
||||
{
|
||||
$this->init($redisClient, $namespace, $defaultLifetime, $marshaller);
|
||||
$this->init($redis, $namespace, $defaultLifetime, $marshaller);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ use Symfony\Component\Cache\Exception\LogicException;
|
||||
use Symfony\Component\Cache\Marshaller\DeflateMarshaller;
|
||||
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
|
||||
use Symfony\Component\Cache\Marshaller\TagAwareMarshaller;
|
||||
use Symfony\Component\Cache\Traits\RedisClusterProxy;
|
||||
use Symfony\Component\Cache\Traits\RedisProxy;
|
||||
use Symfony\Component\Cache\Traits\RedisTrait;
|
||||
|
||||
/**
|
||||
@ -57,18 +59,18 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
|
||||
private $redisEvictionPolicy;
|
||||
|
||||
/**
|
||||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient The redis client
|
||||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis The redis client
|
||||
* @param string $namespace The default namespace
|
||||
* @param int $defaultLifetime The default lifetime
|
||||
*/
|
||||
public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
|
||||
public function __construct($redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
|
||||
{
|
||||
if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getConnection() instanceof ClusterInterface && !$redisClient->getConnection() instanceof PredisCluster) {
|
||||
throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, get_debug_type($redisClient->getConnection())));
|
||||
if ($redis instanceof \Predis\ClientInterface && $redis->getConnection() instanceof ClusterInterface && !$redis->getConnection() instanceof PredisCluster) {
|
||||
throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, get_debug_type($redis->getConnection())));
|
||||
}
|
||||
|
||||
if (\defined('Redis::OPT_COMPRESSION') && ($redisClient instanceof \Redis || $redisClient instanceof \RedisArray || $redisClient instanceof \RedisCluster)) {
|
||||
$compression = $redisClient->getOption(\Redis::OPT_COMPRESSION);
|
||||
if (\defined('Redis::OPT_COMPRESSION') && ($redis instanceof \Redis || $redis instanceof \RedisArray || $redis instanceof \RedisCluster)) {
|
||||
$compression = $redis->getOption(\Redis::OPT_COMPRESSION);
|
||||
|
||||
foreach (\is_array($compression) ? $compression : [$compression] as $c) {
|
||||
if (\Redis::COMPRESSION_NONE !== $c) {
|
||||
@ -77,7 +79,7 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
|
||||
}
|
||||
}
|
||||
|
||||
$this->init($redisClient, $namespace, $defaultLifetime, new TagAwareMarshaller($marshaller));
|
||||
$this->init($redis, $namespace, $defaultLifetime, new TagAwareMarshaller($marshaller));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -274,7 +274,7 @@ class TraceableAdapter implements AdapterInterface, CacheInterface, PruneableInt
|
||||
$this->calls = [];
|
||||
}
|
||||
|
||||
protected function start($name)
|
||||
protected function start(string $name)
|
||||
{
|
||||
$this->calls[] = $event = new TraceableAdapterEvent();
|
||||
$event->name = $name;
|
||||
|
@ -76,15 +76,9 @@ final class CacheItem implements ItemInterface
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function expiresAt($expiration): self
|
||||
public function expiresAt(?\DateTimeInterface $expiration): self
|
||||
{
|
||||
if (null === $expiration) {
|
||||
$this->expiry = null;
|
||||
} elseif ($expiration instanceof \DateTimeInterface) {
|
||||
$this->expiry = (float) $expiration->format('U.u');
|
||||
} else {
|
||||
throw new InvalidArgumentException(sprintf('Expiration date must implement DateTimeInterface or be null, "%s" given.', get_debug_type($expiration)));
|
||||
}
|
||||
$this->expiry = null !== $expiration ? (float) $expiration->format('U.u') : null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -151,7 +145,7 @@ final class CacheItem implements ItemInterface
|
||||
/**
|
||||
* Validates a cache key according to PSR-6.
|
||||
*
|
||||
* @param string $key The key to validate
|
||||
* @param mixed $key The key to validate
|
||||
*
|
||||
* @throws InvalidArgumentException When $key is not valid
|
||||
*/
|
||||
|
@ -238,7 +238,7 @@ class CachePoolPass implements CompilerPassInterface
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function getServiceProvider(ContainerBuilder $container, $name)
|
||||
public static function getServiceProvider(ContainerBuilder $container, string $name)
|
||||
{
|
||||
$container->resolveEnvPlaceholders($name, null, $usedEnvs);
|
||||
|
||||
|
@ -291,14 +291,12 @@ trait AbstractAdapterTrait
|
||||
*
|
||||
* 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)
|
||||
public function enableVersioning(bool $enable = true)
|
||||
{
|
||||
$wasEnabled = $this->versioningIsEnabled;
|
||||
$this->versioningIsEnabled = (bool) $enable;
|
||||
$this->versioningIsEnabled = $enable;
|
||||
$this->namespaceVersion = '';
|
||||
$this->ids = [];
|
||||
|
||||
@ -394,7 +392,7 @@ trait AbstractAdapterTrait
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function handleUnserializeCallback($class)
|
||||
public static function handleUnserializeCallback(string $class)
|
||||
{
|
||||
throw new \DomainException('Class not found: '.$class);
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ trait FilesystemCommonTrait
|
||||
return $ok;
|
||||
}
|
||||
|
||||
protected function doUnlink($file)
|
||||
protected function doUnlink(string $file)
|
||||
{
|
||||
return @unlink($file);
|
||||
}
|
||||
@ -166,7 +166,7 @@ trait FilesystemCommonTrait
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function throwError($type, $message, $file, $line)
|
||||
public static function throwError(int $type, string $message, string $file, int $line)
|
||||
{
|
||||
throw new \ErrorException($message, 0, $type, $file, $line);
|
||||
}
|
||||
|
@ -48,9 +48,9 @@ trait RedisTrait
|
||||
private $marshaller;
|
||||
|
||||
/**
|
||||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient
|
||||
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis
|
||||
*/
|
||||
private function init($redisClient, string $namespace, int $defaultLifetime, ?MarshallerInterface $marshaller)
|
||||
private function init($redis, string $namespace, int $defaultLifetime, ?MarshallerInterface $marshaller)
|
||||
{
|
||||
parent::__construct($namespace, $defaultLifetime);
|
||||
|
||||
@ -58,17 +58,17 @@ trait RedisTrait
|
||||
throw new InvalidArgumentException(sprintf('RedisAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0]));
|
||||
}
|
||||
|
||||
if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy && !$redisClient instanceof RedisClusterProxy) {
|
||||
throw new InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($redisClient)));
|
||||
if (!$redis instanceof \Redis && !$redis instanceof \RedisArray && !$redis instanceof \RedisCluster && !$redis instanceof \Predis\ClientInterface && !$redis instanceof RedisProxy && !$redis instanceof RedisClusterProxy) {
|
||||
throw new InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($redis)));
|
||||
}
|
||||
|
||||
if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getOptions()->exceptions) {
|
||||
$options = clone $redisClient->getOptions();
|
||||
if ($redis instanceof \Predis\ClientInterface && $redis->getOptions()->exceptions) {
|
||||
$options = clone $redis->getOptions();
|
||||
\Closure::bind(function () { $this->options['exceptions'] = false; }, $options, $options)();
|
||||
$redisClient = new $redisClient($redisClient->getConnection(), $options);
|
||||
$redis = new $redis($redis->getConnection(), $options);
|
||||
}
|
||||
|
||||
$this->redis = $redisClient;
|
||||
$this->redis = $redis;
|
||||
$this->marshaller = $marshaller ?? new DefaultMarshaller();
|
||||
}
|
||||
|
||||
@ -82,14 +82,13 @@ trait RedisTrait
|
||||
* - redis:///var/run/redis.sock
|
||||
* - redis://secret@/var/run/redis.sock/13
|
||||
*
|
||||
* @param string $dsn
|
||||
* @param array $options See self::$defaultConnectionOptions
|
||||
*
|
||||
* @throws InvalidArgumentException when the DSN is invalid
|
||||
*
|
||||
* @return \Redis|\RedisCluster|RedisClusterProxy|RedisProxy|\Predis\ClientInterface According to the "class" option
|
||||
*/
|
||||
public static function createConnection($dsn, array $options = [])
|
||||
public static function createConnection(string $dsn, array $options = [])
|
||||
{
|
||||
if (0 === strpos($dsn, 'redis:')) {
|
||||
$scheme = 'redis';
|
||||
@ -487,7 +486,7 @@ trait RedisTrait
|
||||
return $failed;
|
||||
}
|
||||
|
||||
private function pipeline(\Closure $generator, $redis = null): \Generator
|
||||
private function pipeline(\Closure $generator, object $redis = null): \Generator
|
||||
{
|
||||
$ids = [];
|
||||
$redis = $redis ?? $this->redis;
|
||||
|
@ -182,8 +182,10 @@ class ExpressionLanguageTest extends TestCase
|
||||
->expects($this->exactly(1))
|
||||
->method('set')
|
||||
->with($this->isInstanceOf(ParsedExpression::class))
|
||||
->willReturnCallback(function ($parsedExpression) use (&$savedParsedExpression) {
|
||||
->willReturnCallback(function ($parsedExpression) use (&$savedParsedExpression, $cacheItemMock) {
|
||||
$savedParsedExpression = $parsedExpression;
|
||||
|
||||
return $cacheItemMock;
|
||||
})
|
||||
;
|
||||
|
||||
@ -191,6 +193,7 @@ class ExpressionLanguageTest extends TestCase
|
||||
->expects($this->exactly(1))
|
||||
->method('save')
|
||||
->with($cacheItemMock)
|
||||
->willReturn(true)
|
||||
;
|
||||
|
||||
$expression = 'a + b';
|
||||
|
@ -37,20 +37,20 @@ class RedisStore implements SharedLockStoreInterface
|
||||
private $supportTime;
|
||||
|
||||
/**
|
||||
* @param \Redis|\RedisArray|\RedisCluster|RedisProxy|RedisClusterProxy|\Predis\ClientInterface $redisClient
|
||||
* @param float $initialTtl the expiration delay of locks in seconds
|
||||
* @param \Redis|\RedisArray|\RedisCluster|RedisProxy|RedisClusterProxy|\Predis\ClientInterface $redis
|
||||
* @param float $initialTtl The expiration delay of locks in seconds
|
||||
*/
|
||||
public function __construct($redisClient, float $initialTtl = 300.0)
|
||||
public function __construct($redis, float $initialTtl = 300.0)
|
||||
{
|
||||
if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy && !$redisClient instanceof RedisClusterProxy) {
|
||||
throw new InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster, RedisProxy, RedisClusterProxy or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($redisClient)));
|
||||
if (!$redis instanceof \Redis && !$redis instanceof \RedisArray && !$redis instanceof \RedisCluster && !$redis instanceof \Predis\ClientInterface && !$redis instanceof RedisProxy && !$redis instanceof RedisClusterProxy) {
|
||||
throw new InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster, RedisProxy, RedisClusterProxy or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($redis)));
|
||||
}
|
||||
|
||||
if ($initialTtl <= 0) {
|
||||
throw new InvalidTtlException(sprintf('"%s()" expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
|
||||
}
|
||||
|
||||
$this->redis = $redisClient;
|
||||
$this->redis = $redis;
|
||||
$this->initialTtl = $initialTtl;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user