function NormalizerBase::supportsDenormalization

Same name and namespace in other branches
  1. 9 core/modules/serialization/src/Normalizer/NormalizerBase.php \Drupal\serialization\Normalizer\NormalizerBase::supportsDenormalization()
  2. 8.9.x core/modules/serialization/src/Normalizer/NormalizerBase.php \Drupal\serialization\Normalizer\NormalizerBase::supportsDenormalization()
  3. 11.x core/modules/serialization/src/Normalizer/NormalizerBase.php \Drupal\serialization\Normalizer\NormalizerBase::supportsDenormalization()

Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization()

This class doesn't implement DenormalizerInterface, but most of its child classes do. Therefore, this method is implemented at this level to reduce code duplication.

1 method overrides NormalizerBase::supportsDenormalization()
ResourceObjectNormalizer::supportsDenormalization in core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php
Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization()

File

core/modules/serialization/src/Normalizer/NormalizerBase.php, line 53

Class

NormalizerBase
Base class for Normalizers.

Namespace

Drupal\serialization\Normalizer

Code

public function supportsDenormalization($data, string $type, ?string $format = NULL, array $context = []) : bool {
    // If the format is not supported return now.
    if (!$this->checkFormat($format)) {
        return FALSE;
    }
    if (property_exists($this, 'supportedInterfaceOrClass')) {
        @trigger_error('Defining ' . static::class . '::supportedInterfaceOrClass property is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use getSupportedTypes() instead. See https://www.drupal.org/node/3359695', E_USER_DEPRECATED);
        $supported = (array) $this->supportedInterfaceOrClass;
    }
    else {
        $supported = array_keys($this->getSupportedTypes($format));
    }
    $subclass_check = function ($name) use ($type) {
        return (class_exists($name) || interface_exists($name)) && is_subclass_of($type, $name, TRUE);
    };
    return in_array($type, $supported) || array_filter($supported, $subclass_check);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.