Version 1
[yaffs-website] / vendor / symfony / var-dumper / Caster / StubCaster.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 a caster's Stub.
18  *
19  * @author Nicolas Grekas <p@tchwork.com>
20  */
21 class StubCaster
22 {
23     public static function castStub(Stub $c, array $a, Stub $stub, $isNested)
24     {
25         if ($isNested) {
26             $stub->type = $c->type;
27             $stub->class = $c->class;
28             $stub->value = $c->value;
29             $stub->handle = $c->handle;
30             $stub->cut = $c->cut;
31
32             return array();
33         }
34     }
35
36     public static function castCutArray(CutArrayStub $c, array $a, Stub $stub, $isNested)
37     {
38         return $isNested ? $c->preservedSubset : $a;
39     }
40
41     public static function cutInternals($obj, array $a, Stub $stub, $isNested)
42     {
43         if ($isNested) {
44             $stub->cut += count($a);
45
46             return array();
47         }
48
49         return $a;
50     }
51
52     public static function castEnum(EnumStub $c, array $a, Stub $stub, $isNested)
53     {
54         if ($isNested) {
55             $stub->class = '';
56             $stub->handle = 0;
57             $stub->value = null;
58
59             $a = array();
60
61             if ($c->value) {
62                 foreach (array_keys($c->value) as $k) {
63                     $keys[] = !isset($k[0]) || "\0" !== $k[0] ? Caster::PREFIX_VIRTUAL.$k : $k;
64                 }
65                 // Preserve references with array_combine()
66                 $a = array_combine($keys, $c->value);
67             }
68         }
69
70         return $a;
71     }
72 }