Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ObjectNormalizer.php

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\Normalizer

Code

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;
}
RSS feed
Powered by Drupal