Skip to content

Commit b99c855

Browse files
committed
minor symfony#57723 [Cache] fix compatibility with Redis Relay 0.8.1 (xabbuh)
This PR was merged into the 6.4 branch. Discussion ---------- [Cache] fix compatibility with Redis Relay 0.8.1 | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- 4c9445d fix compatibility with Redis Relay 0.8.1
2 parents 85ec307 + 4c9445d commit b99c855

File tree

3 files changed

+179
-7
lines changed

3 files changed

+179
-7
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Relay\Relay;
16+
use Symfony\Component\Cache\Traits\RelayProxy;
1617
use Symfony\Component\VarExporter\LazyProxyTrait;
1718
use Symfony\Component\VarExporter\ProxyHelper;
1819

@@ -62,14 +63,30 @@ public function testRelayProxy()
6263
{
6364
$proxy = file_get_contents(\dirname(__DIR__, 2).'/Traits/RelayProxy.php');
6465
$proxy = substr($proxy, 0, 4 + strpos($proxy, '[];'));
66+
$expectedProxy = $proxy;
6567
$methods = [];
68+
$expectedMethods = [];
69+
70+
foreach ((new \ReflectionClass(RelayProxy::class))->getMethods() as $method) {
71+
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name) || $method->isStatic()) {
72+
continue;
73+
}
74+
75+
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
76+
$expectedMethods[$method->name] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
77+
{
78+
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
79+
}
80+
81+
EOPHP;
82+
}
6683

6784
foreach ((new \ReflectionClass(Relay::class))->getMethods() as $method) {
6885
if ('reset' === $method->name || method_exists(LazyProxyTrait::class, $method->name) || $method->isStatic()) {
6986
continue;
7087
}
7188
$return = $method->getReturnType() instanceof \ReflectionNamedType && 'void' === (string) $method->getReturnType() ? '' : 'return ';
72-
$methods[] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
89+
$methods[$method->name] = "\n ".ProxyHelper::exportSignature($method, false, $args)."\n".<<<EOPHP
7390
{
7491
{$return}(\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args});
7592
}
@@ -80,6 +97,9 @@ public function testRelayProxy()
8097
uksort($methods, 'strnatcmp');
8198
$proxy .= implode('', $methods)."}\n";
8299

83-
$this->assertStringEqualsFile(\dirname(__DIR__, 2).'/Traits/RelayProxy.php', $proxy);
100+
uksort($expectedMethods, 'strnatcmp');
101+
$expectedProxy .= implode('', $expectedMethods)."}\n";
102+
103+
$this->assertEquals($expectedProxy, $proxy);
84104
}
85105
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class RelayProxy extends \Relay\Relay implements ResetInterface, LazyObjectInter
2828
use LazyProxyTrait {
2929
resetLazyObject as reset;
3030
}
31+
use RelayProxyTrait;
3132

3233
private const LAZY_OBJECT_PROPERTY_SCOPES = [];
3334

@@ -291,11 +292,6 @@ public function migrate($host, $port, $key, $dstdb, $timeout, $copy = false, $re
291292
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->migrate(...\func_get_args());
292293
}
293294

294-
public function copy($src, $dst, $options = null): \Relay\Relay|false|int
295-
{
296-
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->copy(...\func_get_args());
297-
}
298-
299295
public function echo($arg): \Relay\Relay|bool|string
300296
{
301297
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->echo(...\func_get_args());
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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('relay'), '0.8.1', '>=')) {
15+
/**
16+
* @internal
17+
*/
18+
trait RelayProxyTrait
19+
{
20+
public function copy($src, $dst, $options = null): \Relay\Relay|bool
21+
{
22+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->copy(...\func_get_args());
23+
}
24+
25+
public function jsonArrAppend($key, $value_or_array, $path = null): \Relay\Relay|array|false
26+
{
27+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonArrAppend(...\func_get_args());
28+
}
29+
30+
public function jsonArrIndex($key, $path, $value, $start = 0, $stop = -1): \Relay\Relay|array|false
31+
{
32+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonArrIndex(...\func_get_args());
33+
}
34+
35+
public function jsonArrInsert($key, $path, $index, $value, ...$other_values): \Relay\Relay|array|false
36+
{
37+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonArrInsert(...\func_get_args());
38+
}
39+
40+
public function jsonArrLen($key, $path = null): \Relay\Relay|array|false
41+
{
42+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonArrLen(...\func_get_args());
43+
}
44+
45+
public function jsonArrPop($key, $path = null, $index = -1): \Relay\Relay|array|false
46+
{
47+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonArrPop(...\func_get_args());
48+
}
49+
50+
public function jsonArrTrim($key, $path, $start, $stop): \Relay\Relay|array|false
51+
{
52+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonArrTrim(...\func_get_args());
53+
}
54+
55+
public function jsonClear($key, $path = null): \Relay\Relay|false|int
56+
{
57+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonClear(...\func_get_args());
58+
}
59+
60+
public function jsonDebug($command, $key, $path = null): \Relay\Relay|false|int
61+
{
62+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonDebug(...\func_get_args());
63+
}
64+
65+
public function jsonDel($key, $path = null): \Relay\Relay|false|int
66+
{
67+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonDel(...\func_get_args());
68+
}
69+
70+
public function jsonForget($key, $path = null): \Relay\Relay|false|int
71+
{
72+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonForget(...\func_get_args());
73+
}
74+
75+
public function jsonGet($key, $options = [], ...$paths): mixed
76+
{
77+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonGet(...\func_get_args());
78+
}
79+
80+
public function jsonMerge($key, $path, $value): \Relay\Relay|bool
81+
{
82+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonMerge(...\func_get_args());
83+
}
84+
85+
public function jsonMget($key_or_array, $path): \Relay\Relay|array|false
86+
{
87+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonMget(...\func_get_args());
88+
}
89+
90+
public function jsonMset($key, $path, $value, ...$other_triples): \Relay\Relay|bool
91+
{
92+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonMset(...\func_get_args());
93+
}
94+
95+
public function jsonNumIncrBy($key, $path, $value): \Relay\Relay|array|false
96+
{
97+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonNumIncrBy(...\func_get_args());
98+
}
99+
100+
public function jsonNumMultBy($key, $path, $value): \Relay\Relay|array|false
101+
{
102+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonNumMultBy(...\func_get_args());
103+
}
104+
105+
public function jsonObjKeys($key, $path = null): \Relay\Relay|array|false
106+
{
107+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonObjKeys(...\func_get_args());
108+
}
109+
110+
public function jsonObjLen($key, $path = null): \Relay\Relay|array|false
111+
{
112+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonObjLen(...\func_get_args());
113+
}
114+
115+
public function jsonResp($key, $path = null): \Relay\Relay|array|false|int|string
116+
{
117+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonResp(...\func_get_args());
118+
}
119+
120+
public function jsonSet($key, $path, $value, $condition = null): \Relay\Relay|bool
121+
{
122+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonSet(...\func_get_args());
123+
}
124+
125+
public function jsonStrAppend($key, $value, $path = null): \Relay\Relay|array|false
126+
{
127+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonStrAppend(...\func_get_args());
128+
}
129+
130+
public function jsonStrLen($key, $path = null): \Relay\Relay|array|false
131+
{
132+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonStrLen(...\func_get_args());
133+
}
134+
135+
public function jsonToggle($key, $path): \Relay\Relay|array|false
136+
{
137+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonToggle(...\func_get_args());
138+
}
139+
140+
public function jsonType($key, $path = null): \Relay\Relay|array|false
141+
{
142+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->jsonType(...\func_get_args());
143+
}
144+
}
145+
} else {
146+
/**
147+
* @internal
148+
*/
149+
trait RelayProxyTrait
150+
{
151+
public function copy($src, $dst, $options = null): \Relay\Relay|false|int
152+
{
153+
return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->copy(...\func_get_args());
154+
}
155+
}
156+
}

0 commit comments

Comments
 (0)