Yaffs site version 1.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             $a = array();
33         }
34
35         return $a;
36     }
37
38     public static function castCutArray(CutArrayStub $c, array $a, Stub $stub, $isNested)
39     {
40         return $isNested ? $c->preservedSubset : $a;
41     }
42
43     public static function cutInternals($obj, array $a, Stub $stub, $isNested)
44     {
45         if ($isNested) {
46             $stub->cut += count($a);
47
48             return array();
49         }
50
51         return $a;
52     }
53
54     public static function castEnum(EnumStub $c, array $a, Stub $stub, $isNested)
55     {
56         if ($isNested) {
57             $stub->class = '';
58             $stub->handle = 0;
59             $stub->value = null;
60
61             $a = array();
62
63             if ($c->value) {
64                 foreach (array_keys($c->value) as $k) {
65                     $keys[] = !isset($k[0]) || "\0" !== $k[0] ? Caster::PREFIX_VIRTUAL.$k : $k;
66                 }
67                 // Preserve references with array_combine()
68                 $a = array_combine($keys, $c->value);
69             }
70         }
71
72         return $a;
73     }
74 }