comparison vendor/symfony/var-dumper/Caster/StubCaster.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
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 $stub->attr = $c->attr;
32
33 if (Stub::TYPE_REF === $c->type && !$c->class && is_string($c->value) && !preg_match('//u', $c->value)) {
34 $stub->type = Stub::TYPE_STRING;
35 $stub->class = Stub::STRING_BINARY;
36 }
37
38 $a = array();
39 }
40
41 return $a;
42 }
43
44 public static function castCutArray(CutArrayStub $c, array $a, Stub $stub, $isNested)
45 {
46 return $isNested ? $c->preservedSubset : $a;
47 }
48
49 public static function cutInternals($obj, array $a, Stub $stub, $isNested)
50 {
51 if ($isNested) {
52 $stub->cut += count($a);
53
54 return array();
55 }
56
57 return $a;
58 }
59
60 public static function castEnum(EnumStub $c, array $a, Stub $stub, $isNested)
61 {
62 if ($isNested) {
63 $stub->class = $c->dumpKeys ? '' : null;
64 $stub->handle = 0;
65 $stub->value = null;
66 $stub->cut = $c->cut;
67 $stub->attr = $c->attr;
68
69 $a = array();
70
71 if ($c->value) {
72 foreach (array_keys($c->value) as $k) {
73 $keys[] = !isset($k[0]) || "\0" !== $k[0] ? Caster::PREFIX_VIRTUAL.$k : $k;
74 }
75 // Preserve references with array_combine()
76 $a = array_combine($keys, $c->value);
77 }
78 }
79
80 return $a;
81 }
82 }