3 namespace Drupal\hal\Normalizer;
5 use Drupal\serialization\Normalizer\NormalizerBase as SerializationNormalizerBase;
6 use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
9 * Base class for Normalizers.
11 abstract class NormalizerBase extends SerializationNormalizerBase implements DenormalizerInterface {
14 * The formats that the Normalizer can handle.
18 protected $formats = ['hal_json'];
23 public function supportsNormalization($data, $format = NULL) {
24 return in_array($format, $this->formats) && parent::supportsNormalization($data, $format);
30 public function supportsDenormalization($data, $type, $format = NULL) {
31 if (in_array($format, $this->formats) && (class_exists($this->supportedInterfaceOrClass) || interface_exists($this->supportedInterfaceOrClass))) {
32 $target = new \ReflectionClass($type);
33 $supported = new \ReflectionClass($this->supportedInterfaceOrClass);
34 if ($supported->isInterface()) {
35 return $target->implementsInterface($this->supportedInterfaceOrClass);
38 return ($target->getName() == $this->supportedInterfaceOrClass || $target->isSubclassOf($this->supportedInterfaceOrClass));