Minor fix to allow DeepNormalize to work as it did before.

This commit is contained in:
Buster "Silver Eagle" Neece 2021-05-31 17:21:19 -05:00
parent b620c378a0
commit 6769b0ce57
No known key found for this signature in database
GPG Key ID: 6D9E12FF03411F4E
1 changed files with 19 additions and 11 deletions

View File

@ -254,20 +254,28 @@ class DoctrineEntityNormalizer extends AbstractNormalizer
$form_mode = $context[self::NORMALIZE_TO_IDENTIFIERS] ?? false;
if (isset($context[self::CLASS_METADATA]->associationMappings[$prop_name])) {
$annotation = $this->annotationReader->getPropertyAnnotation(
new ReflectionProperty(get_class($object), $prop_name),
DeepNormalize::class
);
$reflClass = new ReflectionClass($object);
$reflProp = $reflClass->getProperty($prop_name);
$deep = ($annotation instanceof DeepNormalize)
? $annotation->getDeepNormalize()
: false;
$deepNormalizeAttrs = $reflProp->getAttributes(DeepNormalize::class);
if (!empty($deepNormalizeAttrs)) {
$deepNormalizeAttr = current($deepNormalizeAttrs);
/** @var DeepNormalize $deepNormalize */
$deepNormalize = $deepNormalizeAttr->newInstance();
$deep = $deepNormalize->getDeepNormalize();
} else {
$deep = false;
}
if (!$deep) {
throw new NoGetterAvailableException(sprintf(
'Deep normalization disabled for property %s.',
$prop_name
));
throw new NoGetterAvailableException(
sprintf(
'Deep normalization disabled for property %s.',
$prop_name
)
);
}
$prop_val = $this->getProperty($object, $prop_name);