[VarDumper] Fix anonymous class dumping
This commit is contained in:
parent
6227409060
commit
65da4d5104
@ -55,7 +55,7 @@ class Caster
|
|||||||
if (!isset($k[0]) || ("\0" !== $k[0] && !$reflector->hasProperty($k))) {
|
if (!isset($k[0]) || ("\0" !== $k[0] && !$reflector->hasProperty($k))) {
|
||||||
$p[$i] = self::PREFIX_DYNAMIC.$k;
|
$p[$i] = self::PREFIX_DYNAMIC.$k;
|
||||||
} elseif (isset($k[16]) && "\0" === $k[16] && 0 === strpos($k, "\0class@anonymous\0")) {
|
} 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);
|
$a = array_combine($p, $a);
|
||||||
|
@ -209,14 +209,12 @@ abstract class AbstractCloner implements ClonerInterface
|
|||||||
$class = $stub->class;
|
$class = $stub->class;
|
||||||
|
|
||||||
if (isset($class[15]) && "\0" === $class[15] && 0 === strpos($class, "class@anonymous\x00")) {
|
if (isset($class[15]) && "\0" === $class[15] && 0 === strpos($class, "class@anonymous\x00")) {
|
||||||
$class = get_parent_class($class);
|
$stub->class = get_parent_class($class).'@anonymous';
|
||||||
$stub->class = 'anonymous-'.$class;
|
|
||||||
}
|
}
|
||||||
if (isset($this->classInfo[$class])) {
|
if (isset($this->classInfo[$class])) {
|
||||||
$classInfo = $this->classInfo[$class];
|
$classInfo = $this->classInfo[$class];
|
||||||
} else {
|
} else {
|
||||||
$classInfo = array(
|
$classInfo = array(
|
||||||
$class,
|
|
||||||
new \ReflectionClass($class),
|
new \ReflectionClass($class),
|
||||||
array_reverse(array($class => $class) + class_parents($class) + class_implements($class) + array('*' => '*')),
|
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;
|
$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)])) {
|
if (!empty($this->casters[$p = strtolower($p)])) {
|
||||||
foreach ($this->casters[$p] as $p) {
|
foreach ($this->casters[$p] as $p) {
|
||||||
$a = $this->callCaster($p, $obj, $a, $stub, $isNested);
|
$a = $this->callCaster($p, $obj, $a, $stub, $isNested);
|
||||||
|
@ -157,7 +157,18 @@ class CasterTest extends VarDumperTestCase
|
|||||||
|
|
||||||
$this->assertDumpMatchesFormat(
|
$this->assertDumpMatchesFormat(
|
||||||
<<<'EOTXT'
|
<<<'EOTXT'
|
||||||
anonymous-stdClass {
|
stdClass@anonymous {
|
||||||
|
-foo: "foo"
|
||||||
|
}
|
||||||
|
EOTXT
|
||||||
|
, $c
|
||||||
|
);
|
||||||
|
|
||||||
|
$c = eval('return new class { private $foo = "foo"; };');
|
||||||
|
|
||||||
|
$this->assertDumpMatchesFormat(
|
||||||
|
<<<'EOTXT'
|
||||||
|
@anonymous {
|
||||||
-foo: "foo"
|
-foo: "foo"
|
||||||
}
|
}
|
||||||
EOTXT
|
EOTXT
|
||||||
|
Reference in New Issue
Block a user