function ObjectNormalizer::getAllowedAttributes
Overrides AbstractNormalizer::getAllowedAttributes
File
-
vendor/
symfony/ serializer/ Normalizer/ ObjectNormalizer.php, line 152
Class
- ObjectNormalizer
- Converts between objects and arrays using the PropertyAccess component.
Namespace
Symfony\Component\Serializer\NormalizerCode
protected function getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false) : array|bool {
if (false === ($allowedAttributes = parent::getAllowedAttributes($classOrObject, $context, $attributesAsString))) {
return false;
}
if (null !== $this->classDiscriminatorResolver) {
$class = \is_object($classOrObject) ? $classOrObject::class : $classOrObject;
if (null !== ($discriminatorMapping = $this->classDiscriminatorResolver
->getMappingForMappedObject($classOrObject))) {
$allowedAttributes[] = $attributesAsString ? $discriminatorMapping->getTypeProperty() : new AttributeMetadata($discriminatorMapping->getTypeProperty());
}
if (null !== ($discriminatorMapping = $this->classDiscriminatorResolver
->getMappingForClass($class))) {
$attributes = [];
foreach ($discriminatorMapping->getTypesMapping() as $mappedClass) {
$attributes[] = parent::getAllowedAttributes($mappedClass, $context, $attributesAsString);
}
$allowedAttributes = array_merge($allowedAttributes, ...$attributes);
}
}
return $allowedAttributes;
}