You are here

abstract class NormalizerBase in JSON:API 8

Same name and namespace in other branches
  1. 8.2 src/Normalizer/NormalizerBase.php \Drupal\jsonapi\Normalizer\NormalizerBase

Base normalizer used in all JSON API normalizers.

@internal

Hierarchy

Expanded class hierarchy of NormalizerBase

File

src/Normalizer/NormalizerBase.php, line 12

Namespace

Drupal\jsonapi\Normalizer
View source
abstract class NormalizerBase extends SerializationNormalizerBase {

  /**
   * The formats that the Normalizer can handle.
   *
   * @var array
   */
  protected $formats = [
    'api_json',
  ];

  /**
   * {@inheritdoc}
   */
  public function supportsNormalization($data, $format = NULL) {
    return in_array($format, $this->formats, TRUE) && parent::supportsNormalization($data, $format);
  }

  /**
   * {@inheritdoc}
   */
  public function supportsDenormalization($data, $type, $format = NULL) {
    if (in_array($format, $this->formats, TRUE) && (class_exists($this->supportedInterfaceOrClass) || interface_exists($this->supportedInterfaceOrClass))) {
      $target = new \ReflectionClass($type);
      $supported = new \ReflectionClass($this->supportedInterfaceOrClass);
      if ($supported
        ->isInterface()) {
        return $target
          ->implementsInterface($this->supportedInterfaceOrClass);
      }
      else {
        return $target
          ->getName() == $this->supportedInterfaceOrClass || $target
          ->isSubclassOf($this->supportedInterfaceOrClass);
      }
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY constant Name of key for bubbling cacheability metadata via serialization context.
NormalizerBase::$format protected property List of formats which supports (de-)normalization. 3
NormalizerBase::$formats protected property The formats that the Normalizer can handle. 4
NormalizerBase::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. 22
NormalizerBase::addCacheableDependency protected function Adds cacheability if applicable.
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer. 2
NormalizerBase::supportsDenormalization public function Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() Overrides NormalizerBase::supportsDenormalization
NormalizerBase::supportsNormalization public function Checks whether the given class is supported for normalization by this normalizer. Overrides NormalizerBase::supportsNormalization