Blame view

vendor/symfony/var-dumper/Caster/RedisCaster.php 2.5 KB
c4650843   Etienne Pallier   Ajout du dossier ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\VarDumper\Caster;

use Symfony\Component\VarDumper\Cloner\Stub;

/**
 * Casts Redis class from ext-redis to array representation.
 *
 * @author Nicolas Grekas <p@tchwork.com>
 */
class RedisCaster
{
    private static $serializer = array(
        \Redis::SERIALIZER_NONE => 'NONE',
        \Redis::SERIALIZER_PHP => 'PHP',
        2 => 'IGBINARY', // Optional Redis::SERIALIZER_IGBINARY
    );

c4650843   Etienne Pallier   Ajout du dossier ...
29
30
31
32
    public static function castRedis(\Redis $c, array $a, Stub $stub, $isNested)
    {
        $prefix = Caster::PREFIX_VIRTUAL;

d06254b2   Etienne Pallier   bugfix plugin mig...
33
34
35
36
37
38
39
40
41
        if (\defined('HHVM_VERSION_ID')) {
            if (isset($a[Caster::PREFIX_PROTECTED.'serializer'])) {
                $ser = $a[Caster::PREFIX_PROTECTED.'serializer'];
                $a[Caster::PREFIX_PROTECTED.'serializer'] = isset(self::$serializer[$ser]) ? new ConstStub(self::$serializer[$ser], $ser) : $ser;
            }

            return $a;
        }

c4650843   Etienne Pallier   Ajout du dossier ...
42
43
44
45
46
47
        if (!$connected = $c->isConnected()) {
            return $a + array(
                $prefix.'isConnected' => $connected,
            );
        }

d06254b2   Etienne Pallier   bugfix plugin mig...
48
49
        $ser = $c->getOption(\Redis::OPT_SERIALIZER);
        $retry = \defined('Redis::OPT_SCAN') ? $c->getOption(\Redis::OPT_SCAN) : 0;
c4650843   Etienne Pallier   Ajout du dossier ...
50
51
52
53
54
55

        return $a + array(
            $prefix.'isConnected' => $connected,
            $prefix.'host' => $c->getHost(),
            $prefix.'port' => $c->getPort(),
            $prefix.'auth' => $c->getAuth(),
c4650843   Etienne Pallier   Ajout du dossier ...
56
57
            $prefix.'dbNum' => $c->getDbNum(),
            $prefix.'timeout' => $c->getTimeout(),
c4650843   Etienne Pallier   Ajout du dossier ...
58
            $prefix.'persistentId' => $c->getPersistentID(),
d06254b2   Etienne Pallier   bugfix plugin mig...
59
60
61
62
63
64
            $prefix.'options' => new EnumStub(array(
                'READ_TIMEOUT' => $c->getOption(\Redis::OPT_READ_TIMEOUT),
                'SERIALIZER' => isset(self::$serializer[$ser]) ? new ConstStub(self::$serializer[$ser], $ser) : $ser,
                'PREFIX' => $c->getOption(\Redis::OPT_PREFIX),
                'SCAN' => new ConstStub($retry ? 'RETRY' : 'NORETRY', $retry),
            )),
c4650843   Etienne Pallier   Ajout du dossier ...
65
66
67
68
69
70
71
72
73
74
        );
    }

    public static function castRedisArray(\RedisArray $c, array $a, Stub $stub, $isNested)
    {
        $prefix = Caster::PREFIX_VIRTUAL;

        return $a + array(
            $prefix.'hosts' => $c->_hosts(),
            $prefix.'function' => ClassStub::wrapCallable($c->_function()),
c4650843   Etienne Pallier   Ajout du dossier ...
75
76
        );
    }
c4650843   Etienne Pallier   Ajout du dossier ...
77
}