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

Breadcrumb

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

function AbstractObjectNormalizer::getMappedClass

Return value

class-string

2 calls to AbstractObjectNormalizer::getMappedClass()
AbstractObjectNormalizer::denormalize in vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php
Denormalizes data back into an object of the given class.
AbstractObjectNormalizer::instantiateObject in vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php
Instantiates an object using constructor parameters when needed.

File

vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php, line 1148

Class

AbstractObjectNormalizer
Base class for a normalizer dealing with objects.

Namespace

Symfony\Component\Serializer\Normalizer

Code

private function getMappedClass(array $data, string $class, array $context) : string {
    if (null !== ($object = $this->extractObjectToPopulate($class, $context, self::OBJECT_TO_POPULATE))) {
        return $object::class;
    }
    if (!($mapping = $this->classDiscriminatorResolver?->getMappingForClass($class))) {
        return $class;
    }
    if (null === ($type = $data[$mapping->getTypeProperty()] ?? null)) {
        throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('Type property "%s" not found for the abstract object "%s".', $mapping->getTypeProperty(), $class), null, [
            'string',
        ], isset($context['deserialization_path']) ? $context['deserialization_path'] . '.' . $mapping->getTypeProperty() : $mapping->getTypeProperty(), false);
    }
    if (null === ($mappedClass = $mapping->getClassForType($type))) {
        throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type "%s" is not a valid value.', $type), $type, [
            'string',
        ], isset($context['deserialization_path']) ? $context['deserialization_path'] . '.' . $mapping->getTypeProperty() : $mapping->getTypeProperty(), true);
    }
    return $mappedClass;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal