4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\VarDumper\Caster;
14 use Symfony\Component\VarDumper\Cloner\Stub;
17 * Casts Redis class from ext-redis to array representation.
19 * @author Nicolas Grekas <p@tchwork.com>
23 private static $serializer = array(
24 \Redis::SERIALIZER_NONE => 'NONE',
25 \Redis::SERIALIZER_PHP => 'PHP',
26 2 => 'IGBINARY', // Optional Redis::SERIALIZER_IGBINARY
29 public static function castRedis(\Redis $c, array $a, Stub $stub, $isNested)
31 $prefix = Caster::PREFIX_VIRTUAL;
33 if (defined('HHVM_VERSION_ID')) {
34 if (isset($a[Caster::PREFIX_PROTECTED.'serializer'])) {
35 $ser = $a[Caster::PREFIX_PROTECTED.'serializer'];
36 $a[Caster::PREFIX_PROTECTED.'serializer'] = isset(self::$serializer[$ser]) ? new ConstStub(self::$serializer[$ser], $ser) : $ser;
42 if (!$connected = $c->isConnected()) {
44 $prefix.'isConnected' => $connected,
48 $ser = $c->getOption(\Redis::OPT_SERIALIZER);
49 $retry = defined('Redis::OPT_SCAN') ? $c->getOption(\Redis::OPT_SCAN) : 0;
52 $prefix.'isConnected' => $connected,
53 $prefix.'host' => $c->getHost(),
54 $prefix.'port' => $c->getPort(),
55 $prefix.'auth' => $c->getAuth(),
56 $prefix.'dbNum' => $c->getDbNum(),
57 $prefix.'timeout' => $c->getTimeout(),
58 $prefix.'persistentId' => $c->getPersistentID(),
59 $prefix.'options' => new EnumStub(array(
60 'READ_TIMEOUT' => $c->getOption(\Redis::OPT_READ_TIMEOUT),
61 'SERIALIZER' => isset(self::$serializer[$ser]) ? new ConstStub(self::$serializer[$ser], $ser) : $ser,
62 'PREFIX' => $c->getOption(\Redis::OPT_PREFIX),
63 'SCAN' => new ConstStub($retry ? 'RETRY' : 'NORETRY', $retry),
68 public static function castRedisArray(\RedisArray $c, array $a, Stub $stub, $isNested)
70 $prefix = Caster::PREFIX_VIRTUAL;
73 $prefix.'hosts' => $c->_hosts(),
74 $prefix.'function' => ClassStub::wrapCallable($c->_function()),