You are here

abstract class NormalizerBase in Zircon Profile 8

Same name in this branch
  1. 8 core/modules/hal/src/Normalizer/NormalizerBase.php \Drupal\hal\Normalizer\NormalizerBase
  2. 8 core/modules/serialization/src/Normalizer/NormalizerBase.php \Drupal\serialization\Normalizer\NormalizerBase
Same name and namespace in other branches
  1. 8.0 core/modules/hal/src/Normalizer/NormalizerBase.php \Drupal\hal\Normalizer\NormalizerBase

Base class for Normalizers.

Hierarchy

Expanded class hierarchy of NormalizerBase

File

core/modules/hal/src/Normalizer/NormalizerBase.php, line 16
Contains \Drupal\hal\Normalizer\NormalizerBase.

Namespace

Drupal\hal\Normalizer
View source
abstract class NormalizerBase extends SerializationNormalizerBase implements DenormalizerInterface {

  /**
   * The formats that the Normalizer can handle.
   *
   * @var array
   */
  protected $formats = array(
    'hal_json',
  );

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

  /**
   * {@inheritdoc}
   */
  public function supportsDenormalization($data, $type, $format = NULL) {
    if (in_array($format, $this->formats) && (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
DenormalizerInterface::denormalize public function Denormalizes data back into an object of the given class. 10
NormalizerBase::$formats protected property The formats that the Normalizer can handle.
NormalizerBase::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. 7
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer.
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
NormalizerInterface::normalize public function Normalizes an object into a set of arrays/scalars. 15
SerializerAwareNormalizer::$serializer protected property
SerializerAwareNormalizer::setSerializer public function Sets the owning Serializer object. Overrides SerializerAwareInterface::setSerializer