abstract class NormalizerBase

Same name in this branch

Base class for Normalizers.

Hierarchy

Expanded class hierarchy of NormalizerBase

File

drupal/core/modules/hal/lib/Drupal/hal/Normalizer/NormalizerBase.php, line 17
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',
  );

  /**
   * The entity resolver.
   *
   * @var \Drupal\serialization\EntityResolver\EntityResolverInterface
   */
  protected $entityResolver;

  /**
   * The hypermedia link manager.
   *
   * @var \Drupal\rest\LinkManager\LinkManager
   */
  protected $linkManager;

  /**
   * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::supportsNormalization().
   */
  public function supportsNormalization($data, $format = NULL) {
    return in_array($format, $this->formats) && parent::supportsNormalization($data, $format);
  }

  /**
   * Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization()
   */
  public function supportsDenormalization($data, $type, $format = NULL) {
    if (in_array($format, $this->formats)) {
      $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);
      }
    }
  }

  /**
   * Sets the link manager.
   *
   * The link manager determines the hypermedia type and relation links which
   * correspond to different bundles and fields.
   *
   * @param \Drupal\rest\LinkManager\LinkManager $link_manager
   */
  public function setLinkManager($link_manager) {
    $this->linkManager = $link_manager;
  }

  /**
   * Sets the entity resolver.
   *
   * The entity resolver is used to
   *
   * @param \Drupal\serialization\EntityResolver\EntityResolverInterface $entity_resolver
   */
  public function setEntityResolver(EntityResolverInterface $entity_resolver) {
    $this->entityResolver = $entity_resolver;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DenormalizerInterface::denormalize public function Denormalizes data back into an object of the given class 7
NormalizerBase::$entityResolver protected property The entity resolver.
NormalizerBase::$formats protected property The formats that the Normalizer can handle.
NormalizerBase::$linkManager protected property The hypermedia link manager.
NormalizerBase::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. 6
NormalizerBase::setEntityResolver public function Sets the entity resolver.
NormalizerBase::setLinkManager public function Sets the link manager.
NormalizerBase::supportsDenormalization public function Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() Overrides DenormalizerInterface::supportsDenormalization
NormalizerBase::supportsNormalization public function Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::supportsNormalization(). Overrides NormalizerBase::supportsNormalization
NormalizerInterface::normalize public function Normalizes an object into a set of arrays/scalars 11
SerializerAwareNormalizer::$serializer protected property
SerializerAwareNormalizer::setSerializer public function Sets the owning Serializer object Overrides SerializerAwareInterface::setSerializer