[VarDumper] Fix anonymous class dumping

This commit is contained in:
Nicolas Grekas 2015-10-25 18:17:38 +01:00
parent 6227409060
commit 65da4d5104
3 changed files with 16 additions and 7 deletions

View File

@ -55,7 +55,7 @@ class Caster
if (!isset($k[0]) || ("\0" !== $k[0] && !$reflector->hasProperty($k))) {
$p[$i] = self::PREFIX_DYNAMIC.$k;
} elseif (isset($k[16]) && "\0" === $k[16] && 0 === strpos($k, "\0class@anonymous\0")) {
$p[$i] = "\0anonymous-".$reflector->name.strrchr($k, "\0");
$p[$i] = "\0".$reflector->getParentClass().'@anonymous'.strrchr($k, "\0");
}
}
$a = array_combine($p, $a);

View File

@ -209,14 +209,12 @@ abstract class AbstractCloner implements ClonerInterface
$class = $stub->class;
if (isset($class[15]) && "\0" === $class[15] && 0 === strpos($class, "class@anonymous\x00")) {
$class = get_parent_class($class);
$stub->class = 'anonymous-'.$class;
$stub->class = get_parent_class($class).'@anonymous';
}
if (isset($this->classInfo[$class])) {
$classInfo = $this->classInfo[$class];
} else {
$classInfo = array(
$class,
new \ReflectionClass($class),
array_reverse(array($class => $class) + class_parents($class) + class_implements($class) + array('*' => '*')),
);
@ -224,9 +222,9 @@ abstract class AbstractCloner implements ClonerInterface
$this->classInfo[$class] = $classInfo;
}
$a = $this->callCaster('Symfony\Component\VarDumper\Caster\Caster::castObject', $obj, $classInfo[1], null, $isNested);
$a = $this->callCaster('Symfony\Component\VarDumper\Caster\Caster::castObject', $obj, $classInfo[0], null, $isNested);
foreach ($classInfo[2] as $p) {
foreach ($classInfo[1] as $p) {
if (!empty($this->casters[$p = strtolower($p)])) {
foreach ($this->casters[$p] as $p) {
$a = $this->callCaster($p, $obj, $a, $stub, $isNested);

View File

@ -157,7 +157,18 @@ class CasterTest extends VarDumperTestCase
$this->assertDumpMatchesFormat(
<<<'EOTXT'
anonymous-stdClass {
stdClass@anonymous {
-foo: "foo"
}
EOTXT
, $c
);
$c = eval('return new class { private $foo = "foo"; };');
$this->assertDumpMatchesFormat(
<<<'EOTXT'
@anonymous {
-foo: "foo"
}
EOTXT