Skip to content

Commit d008bd6

Browse files
Merge branch '4.4' into 5.2
* 4.4: [Cache] backport type fixes
2 parents 33c661f + d5f7460 commit d008bd6

15 files changed

+58
-60
lines changed

.github/workflows/integration-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ jobs:
123123
with:
124124
coverage: "none"
125125
extensions: "json,couchbase,memcached,mongodb,redis,rdkafka,xsl,ldap"
126-
ini-values: "memory_limit=-1"
126+
ini-values: date.timezone=Europe/Paris,memory_limit=-1,default_socket_timeout=10,session.gc_probability=0,apc.enable_cli=1,zend.assertions=1
127127
php-version: "${{ matrix.php }}"
128128
tools: pecl
129129

.github/workflows/unit-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
uses: shivammathur/setup-php@v2
4747
with:
4848
coverage: "none"
49-
ini-values: date.timezone=Europe/Paris,memory_limit=-1,default_socket_timeout=10,session.gc_probability=0,apc.enable_cli=1
49+
ini-values: date.timezone=Europe/Paris,memory_limit=-1,default_socket_timeout=10,session.gc_probability=0,apc.enable_cli=1,zend.assertions=1
5050
php-version: "${{ matrix.php }}"
5151
extensions: "${{ env.extensions }}"
5252
tools: flex

src/Symfony/Component/Cache/Adapter/ArrayAdapter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public function reset()
312312
$this->clear();
313313
}
314314

315-
private function generateItems(array $keys, $now, $f)
315+
private function generateItems(array $keys, float $now, \Closure $f)
316316
{
317317
foreach ($keys as $i => $key) {
318318
if (!$isHit = isset($this->expiries[$key]) && ($this->expiries[$key] > $now || !$this->deleteItem($key))) {
@@ -342,7 +342,7 @@ private function generateItems(array $keys, $now, $f)
342342
}
343343
}
344344

345-
private function freeze($value, $key)
345+
private function freeze($value, string $key)
346346
{
347347
if (null === $value) {
348348
return 'N;';

src/Symfony/Component/Cache/Adapter/CouchbaseBucketAdapter.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,15 @@ protected function doFetch(array $ids)
182182
/**
183183
* {@inheritdoc}
184184
*/
185-
protected function doHave($id): bool
185+
protected function doHave(string $id): bool
186186
{
187187
return false !== $this->bucket->get($id);
188188
}
189189

190190
/**
191191
* {@inheritdoc}
192192
*/
193-
protected function doClear($namespace): bool
193+
protected function doClear(string $namespace): bool
194194
{
195195
if ('' === $namespace) {
196196
$this->bucket->manager()->flush();
@@ -221,7 +221,7 @@ protected function doDelete(array $ids): bool
221221
/**
222222
* {@inheritdoc}
223223
*/
224-
protected function doSave(array $values, $lifetime)
224+
protected function doSave(array $values, int $lifetime)
225225
{
226226
if (!$values = $this->marshaller->marshall($values, $failed)) {
227227
return $failed;

src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ protected function doDelete(array $ids)
292292
return $this->doCommonDelete($ids);
293293
}
294294

295-
protected function doUnlink($file)
295+
protected function doUnlink(string $file)
296296
{
297297
unset(self::$valuesCache[$file]);
298298

@@ -323,7 +323,7 @@ class LazyValue
323323
{
324324
public $file;
325325

326-
public function __construct($file)
326+
public function __construct(string $file)
327327
{
328328
$this->file = $file;
329329
}

src/Symfony/Component/Cache/Adapter/RedisAdapter.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@
1212
namespace Symfony\Component\Cache\Adapter;
1313

1414
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
15+
use Symfony\Component\Cache\Traits\RedisClusterProxy;
16+
use Symfony\Component\Cache\Traits\RedisProxy;
1517
use Symfony\Component\Cache\Traits\RedisTrait;
1618

1719
class RedisAdapter extends AbstractAdapter
1820
{
1921
use RedisTrait;
2022

2123
/**
22-
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient The redis client
23-
* @param string $namespace The default namespace
24-
* @param int $defaultLifetime The default lifetime
24+
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis The redis client
25+
* @param string $namespace The default namespace
26+
* @param int $defaultLifetime The default lifetime
2527
*/
26-
public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
28+
public function __construct($redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
2729
{
28-
$this->init($redisClient, $namespace, $defaultLifetime, $marshaller);
30+
$this->init($redis, $namespace, $defaultLifetime, $marshaller);
2931
}
3032
}

src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use Symfony\Component\Cache\Marshaller\DeflateMarshaller;
2121
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
2222
use Symfony\Component\Cache\Marshaller\TagAwareMarshaller;
23+
use Symfony\Component\Cache\Traits\RedisClusterProxy;
24+
use Symfony\Component\Cache\Traits\RedisProxy;
2325
use Symfony\Component\Cache\Traits\RedisTrait;
2426

2527
/**
@@ -57,18 +59,18 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
5759
private $redisEvictionPolicy;
5860

5961
/**
60-
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient The redis client
61-
* @param string $namespace The default namespace
62-
* @param int $defaultLifetime The default lifetime
62+
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis The redis client
63+
* @param string $namespace The default namespace
64+
* @param int $defaultLifetime The default lifetime
6365
*/
64-
public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
66+
public function __construct($redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
6567
{
66-
if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getConnection() instanceof ClusterInterface && !$redisClient->getConnection() instanceof PredisCluster) {
67-
throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, get_debug_type($redisClient->getConnection())));
68+
if ($redis instanceof \Predis\ClientInterface && $redis->getConnection() instanceof ClusterInterface && !$redis->getConnection() instanceof PredisCluster) {
69+
throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, get_debug_type($redis->getConnection())));
6870
}
6971

70-
if (\defined('Redis::OPT_COMPRESSION') && ($redisClient instanceof \Redis || $redisClient instanceof \RedisArray || $redisClient instanceof \RedisCluster)) {
71-
$compression = $redisClient->getOption(\Redis::OPT_COMPRESSION);
72+
if (\defined('Redis::OPT_COMPRESSION') && ($redis instanceof \Redis || $redis instanceof \RedisArray || $redis instanceof \RedisCluster)) {
73+
$compression = $redis->getOption(\Redis::OPT_COMPRESSION);
7274

7375
foreach (\is_array($compression) ? $compression : [$compression] as $c) {
7476
if (\Redis::COMPRESSION_NONE !== $c) {
@@ -77,7 +79,7 @@ public function __construct($redisClient, string $namespace = '', int $defaultLi
7779
}
7880
}
7981

80-
$this->init($redisClient, $namespace, $defaultLifetime, new TagAwareMarshaller($marshaller));
82+
$this->init($redis, $namespace, $defaultLifetime, new TagAwareMarshaller($marshaller));
8183
}
8284

8385
/**

src/Symfony/Component/Cache/Adapter/TraceableAdapter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public function clearCalls()
274274
$this->calls = [];
275275
}
276276

277-
protected function start($name)
277+
protected function start(string $name)
278278
{
279279
$this->calls[] = $event = new TraceableAdapterEvent();
280280
$event->name = $name;

src/Symfony/Component/Cache/CacheItem.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,9 @@ public function set($value): self
7676
*
7777
* @return $this
7878
*/
79-
public function expiresAt($expiration): self
79+
public function expiresAt(?\DateTimeInterface $expiration): self
8080
{
81-
if (null === $expiration) {
82-
$this->expiry = null;
83-
} elseif ($expiration instanceof \DateTimeInterface) {
84-
$this->expiry = (float) $expiration->format('U.u');
85-
} else {
86-
throw new InvalidArgumentException(sprintf('Expiration date must implement DateTimeInterface or be null, "%s" given.', get_debug_type($expiration)));
87-
}
81+
$this->expiry = null !== $expiration ? (float) $expiration->format('U.u') : null;
8882

8983
return $this;
9084
}
@@ -151,7 +145,7 @@ public function getMetadata(): array
151145
/**
152146
* Validates a cache key according to PSR-6.
153147
*
154-
* @param string $key The key to validate
148+
* @param mixed $key The key to validate
155149
*
156150
* @throws InvalidArgumentException When $key is not valid
157151
*/

src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private function getNamespace(string $seed, string $id)
238238
/**
239239
* @internal
240240
*/
241-
public static function getServiceProvider(ContainerBuilder $container, $name)
241+
public static function getServiceProvider(ContainerBuilder $container, string $name)
242242
{
243243
$container->resolveEnvPlaceholders($name, null, $usedEnvs);
244244

src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,12 @@ public function saveDeferred(CacheItemInterface $item)
291291
*
292292
* Calling this method also clears the memoized namespace version and thus forces a resynchonization of it.
293293
*
294-
* @param bool $enable
295-
*
296294
* @return bool the previous state of versioning
297295
*/
298-
public function enableVersioning($enable = true)
296+
public function enableVersioning(bool $enable = true)
299297
{
300298
$wasEnabled = $this->versioningIsEnabled;
301-
$this->versioningIsEnabled = (bool) $enable;
299+
$this->versioningIsEnabled = $enable;
302300
$this->namespaceVersion = '';
303301
$this->ids = [];
304302

@@ -394,7 +392,7 @@ private function getId($key)
394392
/**
395393
* @internal
396394
*/
397-
public static function handleUnserializeCallback($class)
395+
public static function handleUnserializeCallback(string $class)
398396
{
399397
throw new \DomainException('Class not found: '.$class);
400398
}

src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function doDelete(array $ids)
8383
return $ok;
8484
}
8585

86-
protected function doUnlink($file)
86+
protected function doUnlink(string $file)
8787
{
8888
return @unlink($file);
8989
}
@@ -166,7 +166,7 @@ private function scanHashDir(string $directory): \Generator
166166
/**
167167
* @internal
168168
*/
169-
public static function throwError($type, $message, $file, $line)
169+
public static function throwError(int $type, string $message, string $file, int $line)
170170
{
171171
throw new \ErrorException($message, 0, $type, $file, $line);
172172
}

src/Symfony/Component/Cache/Traits/RedisTrait.php

+11-12
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,27 @@ trait RedisTrait
4848
private $marshaller;
4949

5050
/**
51-
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient
51+
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis
5252
*/
53-
private function init($redisClient, string $namespace, int $defaultLifetime, ?MarshallerInterface $marshaller)
53+
private function init($redis, string $namespace, int $defaultLifetime, ?MarshallerInterface $marshaller)
5454
{
5555
parent::__construct($namespace, $defaultLifetime);
5656

5757
if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) {
5858
throw new InvalidArgumentException(sprintf('RedisAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0]));
5959
}
6060

61-
if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy && !$redisClient instanceof RedisClusterProxy) {
62-
throw new InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($redisClient)));
61+
if (!$redis instanceof \Redis && !$redis instanceof \RedisArray && !$redis instanceof \RedisCluster && !$redis instanceof \Predis\ClientInterface && !$redis instanceof RedisProxy && !$redis instanceof RedisClusterProxy) {
62+
throw new InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($redis)));
6363
}
6464

65-
if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getOptions()->exceptions) {
66-
$options = clone $redisClient->getOptions();
65+
if ($redis instanceof \Predis\ClientInterface && $redis->getOptions()->exceptions) {
66+
$options = clone $redis->getOptions();
6767
\Closure::bind(function () { $this->options['exceptions'] = false; }, $options, $options)();
68-
$redisClient = new $redisClient($redisClient->getConnection(), $options);
68+
$redis = new $redis($redis->getConnection(), $options);
6969
}
7070

71-
$this->redis = $redisClient;
71+
$this->redis = $redis;
7272
$this->marshaller = $marshaller ?? new DefaultMarshaller();
7373
}
7474

@@ -82,14 +82,13 @@ private function init($redisClient, string $namespace, int $defaultLifetime, ?Ma
8282
* - redis:///var/run/redis.sock
8383
* - redis://secret@/var/run/redis.sock/13
8484
*
85-
* @param string $dsn
86-
* @param array $options See self::$defaultConnectionOptions
85+
* @param array $options See self::$defaultConnectionOptions
8786
*
8887
* @throws InvalidArgumentException when the DSN is invalid
8988
*
9089
* @return \Redis|\RedisCluster|RedisClusterProxy|RedisProxy|\Predis\ClientInterface According to the "class" option
9190
*/
92-
public static function createConnection($dsn, array $options = [])
91+
public static function createConnection(string $dsn, array $options = [])
9392
{
9493
if (0 === strpos($dsn, 'redis:')) {
9594
$scheme = 'redis';
@@ -487,7 +486,7 @@ protected function doSave(array $values, int $lifetime)
487486
return $failed;
488487
}
489488

490-
private function pipeline(\Closure $generator, $redis = null): \Generator
489+
private function pipeline(\Closure $generator, object $redis = null): \Generator
491490
{
492491
$ids = [];
493492
$redis = $redis ?? $this->redis;

src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,18 @@ public function testCachingWithDifferentNamesOrder()
182182
->expects($this->exactly(1))
183183
->method('set')
184184
->with($this->isInstanceOf(ParsedExpression::class))
185-
->willReturnCallback(function ($parsedExpression) use (&$savedParsedExpression) {
185+
->willReturnCallback(function ($parsedExpression) use (&$savedParsedExpression, $cacheItemMock) {
186186
$savedParsedExpression = $parsedExpression;
187+
188+
return $cacheItemMock;
187189
})
188190
;
189191

190192
$cacheMock
191193
->expects($this->exactly(1))
192194
->method('save')
193195
->with($cacheItemMock)
196+
->willReturn(true)
194197
;
195198

196199
$expression = 'a + b';

src/Symfony/Component/Lock/Store/RedisStore.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ class RedisStore implements SharedLockStoreInterface
3737
private $supportTime;
3838

3939
/**
40-
* @param \Redis|\RedisArray|\RedisCluster|RedisProxy|RedisClusterProxy|\Predis\ClientInterface $redisClient
41-
* @param float $initialTtl the expiration delay of locks in seconds
40+
* @param \Redis|\RedisArray|\RedisCluster|RedisProxy|RedisClusterProxy|\Predis\ClientInterface $redis
41+
* @param float $initialTtl The expiration delay of locks in seconds
4242
*/
43-
public function __construct($redisClient, float $initialTtl = 300.0)
43+
public function __construct($redis, float $initialTtl = 300.0)
4444
{
45-
if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy && !$redisClient instanceof RedisClusterProxy) {
46-
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)));
45+
if (!$redis instanceof \Redis && !$redis instanceof \RedisArray && !$redis instanceof \RedisCluster && !$redis instanceof \Predis\ClientInterface && !$redis instanceof RedisProxy && !$redis instanceof RedisClusterProxy) {
46+
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)));
4747
}
4848

4949
if ($initialTtl <= 0) {
5050
throw new InvalidTtlException(sprintf('"%s()" expects a strictly positive TTL. Got %d.', __METHOD__, $initialTtl));
5151
}
5252

53-
$this->redis = $redisClient;
53+
$this->redis = $redis;
5454
$this->initialTtl = $initialTtl;
5555
}
5656

0 commit comments

Comments
 (0)