Skip to content

Commit 223a9b2

Browse files
committed
fix ext-redis 6.2.0 compatibility
1 parent d46e8e7 commit 223a9b2

File tree

7 files changed

+114
-13
lines changed

7 files changed

+114
-13
lines changed

src/Symfony/Component/Cache/Tests/Traits/RedisProxiesTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public function testRedisProxy($class)
3434
$methods = [];
3535

3636
foreach ((new \ReflectionClass(\sprintf('Symfony\Component\Cache\Traits\\%s%dProxy', $class, $version)))->getMethods() as $method) {
37-
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
37+
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name) || $method->isInternal()) {
3838
continue;
3939
}
40-
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
41-
$methods[$method->name] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
40+
$return = '__construct' === $method->name || $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
41+
$methods[$method->name] = "\n ".ProxyHelper::exportSignature($method, true, $args)."\n".<<<EOPHP
4242
{
4343
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
4444
}
@@ -52,10 +52,10 @@ public function testRedisProxy($class)
5252
$methods = [];
5353

5454
foreach ((new \ReflectionClass($class))->getMethods() as $method) {
55-
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name)) {
55+
if ('__destruct' === $method->name || 'reset' === $method->name) {
5656
continue;
5757
}
58-
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
58+
$return = '__construct' === $method->name || $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
5959
$methods[$method->name] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
6060
{
6161
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
@@ -91,7 +91,7 @@ public function testRelayProxy()
9191
continue;
9292
}
9393

94-
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
94+
$return = '__construct' === $method->name || $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
9595
$expectedMethods[$method->name] = "\n ".ProxyHelper::exportSignature($method, true, $args)."\n".<<<EOPHP
9696
{
9797
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
@@ -104,7 +104,7 @@ public function testRelayProxy()
104104
if ('__destruct' === $method->name || 'reset' === $method->name || $method->isStatic()) {
105105
continue;
106106
}
107-
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
107+
$return = '__construct' === $method->name || $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
108108
$methods[$method->name] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
109109
{
110110
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});

src/Symfony/Component/Cache/Traits/Redis6ProxyTrait.php renamed to src/Symfony/Component/Cache/Traits/Redis61ProxyTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/**
1616
* @internal
1717
*/
18-
trait Redis6ProxyTrait
18+
trait Redis61ProxyTrait
1919
{
2020
public function dump($key): \Redis|string|false
2121
{
@@ -51,7 +51,7 @@ public function waitaof($numlocal, $numreplicas, $timeout): \Redis|array|false
5151
/**
5252
* @internal
5353
*/
54-
trait Redis6ProxyTrait
54+
trait Redis61ProxyTrait
5555
{
5656
public function dump($key): \Redis|string
5757
{
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Traits;
13+
14+
if (version_compare(phpversion('redis'), '6.2.0', '>=')) {
15+
/**
16+
* @internal
17+
*/
18+
trait Redis62ProxyTrait
19+
{
20+
public function expiremember($key, $field, $ttl, $unit = null): \Redis|false|int
21+
{
22+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->expiremember(...\func_get_args());
23+
}
24+
25+
public function expirememberat($key, $field, $timestamp): \Redis|false|int
26+
{
27+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->expirememberat(...\func_get_args());
28+
}
29+
30+
public function getWithMeta($key): \Redis|array|false
31+
{
32+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->getWithMeta(...\func_get_args());
33+
}
34+
35+
public function serverName(): false|string
36+
{
37+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->serverName(...\func_get_args());
38+
}
39+
40+
public function serverVersion(): false|string
41+
{
42+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->serverVersion(...\func_get_args());
43+
}
44+
}
45+
} else {
46+
/**
47+
* @internal
48+
*/
49+
trait Redis62ProxyTrait
50+
{
51+
}
52+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
2525
*/
2626
class Redis6Proxy extends \Redis implements ResetInterface, LazyObjectInterface
2727
{
28-
use Redis6ProxyTrait;
28+
use Redis61ProxyTrait;
29+
use Redis62ProxyTrait;
2930
use LazyProxyTrait {
3031
resetLazyObject as reset;
3132
}

src/Symfony/Component/Cache/Traits/RedisCluster6ProxyTrait.php renamed to src/Symfony/Component/Cache/Traits/RedisCluster61ProxyTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/**
1616
* @internal
1717
*/
18-
trait RedisCluster6ProxyTrait
18+
trait RedisCluster61ProxyTrait
1919
{
2020
public function getex($key, $options = []): \RedisCluster|string|false
2121
{
@@ -36,7 +36,7 @@ public function waitaof($key_or_address, $numlocal, $numreplicas, $timeout): \Re
3636
/**
3737
* @internal
3838
*/
39-
trait RedisCluster6ProxyTrait
39+
trait RedisCluster61ProxyTrait
4040
{
4141
public function publish($channel, $message): \RedisCluster|bool
4242
{
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Cache\Traits;
13+
14+
if (version_compare(phpversion('redis'), '6.2.0', '>=')) {
15+
/**
16+
* @internal
17+
*/
18+
trait RedisCluster62ProxyTrait
19+
{
20+
public function expiremember($key, $field, $ttl, $unit = null): \Redis|false|int
21+
{
22+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->expiremember(...\func_get_args());
23+
}
24+
25+
public function expirememberat($key, $field, $timestamp): \Redis|false|int
26+
{
27+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->expirememberat(...\func_get_args());
28+
}
29+
30+
public function getdel($key): mixed
31+
{
32+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->getdel(...\func_get_args());
33+
}
34+
35+
public function getWithMeta($key): \RedisCluster|array|false
36+
{
37+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->getWithMeta(...\func_get_args());
38+
}
39+
}
40+
} else {
41+
/**
42+
* @internal
43+
*/
44+
trait RedisCluster62ProxyTrait
45+
{
46+
}
47+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
2525
*/
2626
class RedisCluster6Proxy extends \RedisCluster implements ResetInterface, LazyObjectInterface
2727
{
28-
use RedisCluster6ProxyTrait;
28+
use RedisCluster61ProxyTrait;
29+
use RedisCluster62ProxyTrait;
2930
use LazyProxyTrait {
3031
resetLazyObject as reset;
3132
}

0 commit comments

Comments
 (0)