[VarExporter] fix dumping private properties from abstract classes
This commit is contained in:
parent
4548a44a01
commit
b10e2638a4
@ -125,7 +125,8 @@ class Exporter
|
||||
$c = 'stdClass';
|
||||
} elseif ('*' === $n[1]) {
|
||||
$n = substr($n, 3);
|
||||
if ('Error' === $c = $class) {
|
||||
$c = $reflector->getProperty($n)->class;
|
||||
if ('Error' === $c) {
|
||||
$c = 'TypeError';
|
||||
} elseif ('Exception' === $c) {
|
||||
$c = 'ErrorException';
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\VarExporter\Internal;
|
||||
|
||||
use Symfony\Component\VarExporter\Exception\ClassNotFoundException;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
@ -59,7 +61,10 @@ class Hydrator
|
||||
};
|
||||
}
|
||||
|
||||
$classReflector = Registry::$reflectors[$class] ?? Registry::getClassReflector($class);
|
||||
if (!\class_exists($class) && !\interface_exists($class, false) && !\trait_exists($class, false)) {
|
||||
throw new ClassNotFoundException($class);
|
||||
}
|
||||
$classReflector = new \ReflectionClass($class);
|
||||
|
||||
if (!$classReflector->isInternal()) {
|
||||
return self::$hydrators[$class] = (self::$hydrators['stdClass'] ?? self::getHydrator('stdClass'))->bindTo(null, $class);
|
||||
|
@ -6,10 +6,13 @@ return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
|
||||
],
|
||||
null,
|
||||
[
|
||||
'Symfony\\Component\\VarExporter\\Tests\\ConcreteClass' => [
|
||||
'Symfony\\Component\\VarExporter\\Tests\\AbstractClass' => [
|
||||
'foo' => [
|
||||
123,
|
||||
],
|
||||
'bar' => [
|
||||
234,
|
||||
],
|
||||
],
|
||||
],
|
||||
$o[0],
|
||||
|
@ -6,7 +6,7 @@ return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
|
||||
]),
|
||||
null,
|
||||
[
|
||||
'Symfony\\Component\\VarExporter\\Tests\\FinalError' => [
|
||||
'TypeError' => [
|
||||
'file' => [
|
||||
\dirname(__DIR__).\DIRECTORY_SEPARATOR.'VarExporterTest.php',
|
||||
],
|
||||
|
@ -10,17 +10,13 @@ return \Symfony\Component\VarExporter\Internal\Hydrator::hydrate(
|
||||
'Symfony\\Component\\VarExporter\\Tests\\MyPrivateValue' => [
|
||||
'prot' => [
|
||||
123,
|
||||
123,
|
||||
],
|
||||
'priv' => [
|
||||
234,
|
||||
234,
|
||||
],
|
||||
],
|
||||
'Symfony\\Component\\VarExporter\\Tests\\MyPrivateChildValue' => [
|
||||
'prot' => [
|
||||
1 => 123,
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
$o[0],
|
||||
|
@ -326,6 +326,12 @@ final class FinalStdClass extends \stdClass
|
||||
abstract class AbstractClass
|
||||
{
|
||||
protected $foo;
|
||||
private $bar;
|
||||
|
||||
protected function setBar($bar)
|
||||
{
|
||||
$this->bar = $bar;
|
||||
}
|
||||
}
|
||||
|
||||
class ConcreteClass extends AbstractClass
|
||||
@ -333,5 +339,6 @@ class ConcreteClass extends AbstractClass
|
||||
public function __construct()
|
||||
{
|
||||
$this->foo = 123;
|
||||
$this->setBar(234);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user