bug #25053 [Serializer] Fixing PropertyNormalizer supports parent properties (Christopher Hertel)
This PR was merged into the 3.4 branch. Discussion ---------- [Serializer] Fixing PropertyNormalizer supports parent properties | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a With5ecafc5e25
support for parent properties was added to 3.4, but supports method was not updated for child classes without properties. Commits -------a879e4f
fixing that PropertyNormalizer supports parent properties
This commit is contained in:
commit
961981577d
@ -60,11 +60,13 @@ class PropertyNormalizer extends AbstractObjectNormalizer
|
|||||||
$class = new \ReflectionClass($class);
|
$class = new \ReflectionClass($class);
|
||||||
|
|
||||||
// We look for at least one non-static property
|
// We look for at least one non-static property
|
||||||
foreach ($class->getProperties() as $property) {
|
do {
|
||||||
if (!$property->isStatic()) {
|
foreach ($class->getProperties() as $property) {
|
||||||
return true;
|
if (!$property->isStatic()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} while ($class = $class->getParentClass());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -441,6 +441,11 @@ class PropertyNormalizerTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testInheritedPropertiesSupport()
|
||||||
|
{
|
||||||
|
$this->assertTrue($this->normalizer->supportsNormalization(new PropertyChildDummy()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PropertyDummy
|
class PropertyDummy
|
||||||
@ -509,3 +514,12 @@ class StaticPropertyDummy
|
|||||||
{
|
{
|
||||||
private static $property = 'value';
|
private static $property = 'value';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PropertyParentDummy
|
||||||
|
{
|
||||||
|
private $foo = 'bar';
|
||||||
|
}
|
||||||
|
|
||||||
|
class PropertyChildDummy extends PropertyParentDummy
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user