4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\VarDumper\Caster;
14 use Symfony\Component\VarDumper\Cloner\Stub;
17 * Casts a caster's Stub.
19 * @author Nicolas Grekas <p@tchwork.com>
23 public static function castStub(Stub $c, array $a, Stub $stub, $isNested)
26 $stub->type = $c->type;
27 $stub->class = $c->class;
28 $stub->value = $c->value;
29 $stub->handle = $c->handle;
31 $stub->attr = $c->attr;
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;
44 public static function castCutArray(CutArrayStub $c, array $a, Stub $stub, $isNested)
46 return $isNested ? $c->preservedSubset : $a;
49 public static function cutInternals($obj, array $a, Stub $stub, $isNested)
52 $stub->cut += \count($a);
60 public static function castEnum(EnumStub $c, array $a, Stub $stub, $isNested)
63 $stub->class = $c->dumpKeys ? '' : null;
67 $stub->attr = $c->attr;
72 foreach (array_keys($c->value) as $k) {
73 $keys[] = !isset($k[0]) || "\0" !== $k[0] ? Caster::PREFIX_VIRTUAL.$k : $k;
75 // Preserve references with array_combine()
76 $a = array_combine($keys, $c->value);