8000 [VarDumper] Add Relay support · symfony/symfony@0c67250 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c67250

Browse files
committed
[VarDumper] Add Relay support
1 parent ab13492 commit 0c67250

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

src/Symfony/Component/VarDumper/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Add caster for `WeakMap`
88
* Add support of named arguments to `dd()` and `dump()` to display the argument name
9+
* Add support for `Relay\Relay`
910

1011
6.2
1112
---

src/Symfony/Component/VarDumper/Caster/RedisCaster.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\VarDumper\Caster;
1313

14+
use Relay\Relay;
1415
use Symfony\Component\VarDumper\Cloner\Stub;
1516

1617
/**
@@ -23,15 +24,15 @@
2324
class RedisCaster
2425
{
2526
private const SERIALIZERS = [
26-
8000 \Redis::SERIALIZER_NONE => 'NONE',
27-
\Redis::SERIALIZER_PHP => 'PHP',
27+
0 => 'NONE', // Redis::SERIALIZER_NONE
28+
1 => 'PHP', // Redis::SERIALIZER_PHP
2829
2 => 'IGBINARY', // Optional Redis::SERIALIZER_IGBINARY
2930
];
3031

3132
private const MODES = [
32-
\Redis::ATOMIC => 'ATOMIC',
33-
\Redis::MULTI => 'MULTI',
34-
\Redis::PIPELINE => 'PIPELINE',
33+
0 => 'ATOMIC', // Redis::ATOMIC
34+
1 => 'MULTI', // Redis::MULTI
35+
2 => 'PIPELINE', // Redis::PIPELINE
3536
];
3637

3738
private const COMPRESSION_MODES = [
@@ -46,7 +47,7 @@ class RedisCaster
4647
\RedisCluster::FAILOVER_DISTRIBUTE_SLAVES => 'DISTRIBUTE_SLAVES',
4748
];
4849

49-
public static function castRedis(\Redis $c, array $a, Stub $stub, bool $isNested)
50+
public static function castRedis(\Redis|Relay $c, array $a, Stub $stub, bool $isNested)
5051
{
5152
$prefix = Caster::PREFIX_VIRTUAL;
5253

@@ -102,9 +103,9 @@ public static function castRedisCluster(\RedisCluster $c, array $a, Stub $stub,
102103
return $a;
103104
}
104105

105-
private static function getRedisOptions(\Redis|\RedisArray|\RedisCluster $redis, array $options = []): EnumStub
106+
private static function getRedisOptions(\Redis|Relay|\RedisArray|\RedisCluster $redis, array $options = []): EnumStub
106107
{
107-
$serializer = $redis->getOption(\Redis::OPT_SERIALIZER);
108+
$serializer = $redis->getOption(\defined('Redis::OPT_SERIALIZER') ? \Redis::OPT_SERIALIZER : 1);
108109
if (\is_array($serializer)) {
109110
foreach ($serializer as &$v) {
110111
if (isset(self::SERIALIZERS[$v])) {
@@ -137,10 +138,10 @@ private static function getRedisOptions(\Redis|\RedisArray|\RedisCluster $redis,
137138

138139
$options += [
139140
'TCP_KEEPALIVE' => \defined('Redis::OPT_TCP_KEEPALIVE') ? $redis->getOption(\Redis::OPT_TCP_KEEPALIVE) : 0,
140-
'READ_TIMEOUT' => $redis->getOption(\Redis::OPT_READ_TIMEOUT),
141+
'READ_TIMEOUT' => $redis->getOption(\defined('Redis::OPT_READ_TIMEOUT') ? \Redis::OPT_READ_TIMEOUT : 3),
141142
'COMPRESSION' => $compression,
142143
'SERIALIZER' => $serializer,
143-
'PREFIX' => $redis->getOption(\Redis::OPT_PREFIX),
144+
'PREFIX' => $redis->getOption(\defined('Redis::OPT_PREFIX') ? \Redis::OPT_PREFIX : 2),
144145
'SCAN' => $retry,
145146
];
146147

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ abstract class AbstractCloner implements ClonerInterface
130130
'WeakReference' => ['Symfony\Component\VarDumper\Caster\SplCaster', 'castWeakReference'],
131131

132132
'Redis' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedis'],
133+
'Relay\Relay' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedis'],
133134
'RedisArray' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisArray'],
134135
'RedisCluster' => ['Symfony\Component\VarDumper\Caster\RedisCaster', 'castRedisCluster'],
135136

src/Symfony/Component/VarDumper/Tests/Caster/RedisCasterTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/**
1818
* @author Nicolas Grekas <p@tchwork.com>
1919
* @requires extension redis
20+
* @requires extension relay
2021
* @group integration
2122
*/
2223
class RedisCasterTest extends TestCase
@@ -36,18 +37,22 @@ public function testNotConnected()
3637
$this->assertDumpMatchesFormat($xCast, $redis);
3738
}
3839

39-
public function testConnected()
40+
/**
41+
* @testWith ["Redis"]
42+
* ["Relay\\Relay"]
43+
*/
44+
public function testConnected(string $class)
4045
{
4146
$redisHost = explode(':', getenv('REDIS_HOST')) + [1 => 6379];
42-
$redis = new \Redis();
47+
$redis = new $class;
4348
try {
4449
$redis->connect(...$redisHost);
4550
} catch (\Exception $e) {
4651
self::markTestSkipped($e->getMessage());
4752
}
4853

4954
$xCast = <<<EODUMP
50-
Redis {%A
55+
%a {%A
5156
isConnected: true
5257
host: "{$redisHost[0]}"
5358
port: {$redisHost[1]}
@@ -56,9 +61,9 @@ public function testConnected()
5661
dbNum: 0
5762
timeout: 0.0
5863
lastError: null
59-
persistentId: null
64+
persistentId: %a
6065
options: {
61-
TCP_KEEPALIVE: 0
66+
TCP_KEEPALIVE: %a
6267
READ_TIMEOUT: 0.0
6368
COMPRESSION: NONE
6469
SERIALIZER: NONE

0 commit comments

Comments
 (0)
0