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

Breadcrumb

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

class CustomNormalizer

@author Jordi Boggiano <j.boggiano@seld.be>

Hierarchy

  • class \Symfony\Component\Serializer\Normalizer\CustomNormalizer implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface, \Symfony\Component\Serializer\Normalizer\DenormalizerInterface, \Symfony\Component\Serializer\SerializerAwareInterface uses \Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait, \Symfony\Component\Serializer\SerializerAwareTrait

Expanded class hierarchy of CustomNormalizer

File

vendor/symfony/serializer/Normalizer/CustomNormalizer.php, line 20

Namespace

Symfony\Component\Serializer\Normalizer
View source
final class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface {
    use ObjectToPopulateTrait;
    use SerializerAwareTrait;
    public function getSupportedTypes(?string $format) : array {
        return [
            NormalizableInterface::class => true,
            DenormalizableInterface::class => true,
        ];
    }
    public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null {
        return $object->normalize($this->serializer, $format, $context);
    }
    public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []) : mixed {
        $object = $this->extractObjectToPopulate($type, $context) ?? new $type();
        $object->denormalize($this->serializer, $data, $format, $context);
        return $object;
    }
    
    /**
     * Checks if the given class implements the NormalizableInterface.
     *
     * @param mixed       $data   Data to normalize
     * @param string|null $format The format being (de-)serialized from or into
     */
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []) : bool {
        return $data instanceof NormalizableInterface;
    }
    
    /**
     * Checks if the given class implements the DenormalizableInterface.
     *
     * @param mixed       $data   Data to denormalize from
     * @param string      $type   The class to which the data should be denormalized
     * @param string|null $format The format being deserialized from
     */
    public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []) : bool {
        return is_subclass_of($type, DenormalizableInterface::class);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
CustomNormalizer::denormalize public function Denormalizes data back into an object of the given class. Overrides DenormalizerInterface::denormalize
CustomNormalizer::getSupportedTypes public function Returns the types potentially supported by this normalizer. Overrides NormalizerInterface::getSupportedTypes
CustomNormalizer::normalize public function Normalizes data into a set of arrays/scalars. Overrides NormalizerInterface::normalize
CustomNormalizer::supportsDenormalization public function Checks if the given class implements the DenormalizableInterface. Overrides DenormalizerInterface::supportsDenormalization
CustomNormalizer::supportsNormalization public function Checks if the given class implements the NormalizableInterface. Overrides NormalizerInterface::supportsNormalization
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS public constant
ObjectToPopulateTrait::extractObjectToPopulate protected function Extract the `object_to_populate` field from the context if it exists
and is an instance of the provided $class.
SerializerAwareTrait::$serializer protected property
SerializerAwareTrait::setSerializer public function
RSS feed
Powered by Drupal