Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / var-dumper / Caster / RedisCaster.php
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\VarDumper\Caster;
13
14 use Symfony\Component\VarDumper\Cloner\Stub;
15
16 /**
17  * Casts Redis class from ext-redis to array representation.
18  *
19  * @author Nicolas Grekas <p@tchwork.com>
20  */
21 class RedisCaster
22 {
23     private static $serializer = array(
24         \Redis::SERIALIZER_NONE => 'NONE',
25         \Redis::SERIALIZER_PHP => 'PHP',
26         2 => 'IGBINARY', // Optional Redis::SERIALIZER_IGBINARY
27     );
28
29     public static function castRedis(\Redis $c, array $a, Stub $stub, $isNested)
30     {
31         $prefix = Caster::PREFIX_VIRTUAL;
32
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;
37             }
38
39             return $a;
40         }
41
42         if (!$connected = $c->isConnected()) {
43             return $a + array(
44                 $prefix.'isConnected' => $connected,
45             );
46         }
47
48         $ser = $c->getOption(\Redis::OPT_SERIALIZER);
49         $retry = defined('Redis::OPT_SCAN') ? $c->getOption(\Redis::OPT_SCAN) : 0;
50
51         return $a + array(
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),
64             )),
65         );
66     }
67
68     public static function castRedisArray(\RedisArray $c, array $a, Stub $stub, $isNested)
69     {
70         $prefix = Caster::PREFIX_VIRTUAL;
71
72         return $a + array(
73             $prefix.'hosts' => $c->_hosts(),
74             $prefix.'function' => ClassStub::wrapCallable($c->_function()),
75         );
76     }
77 }