From d66888c36cdbd08f4cf712dd08e44b3eeb059752 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Tue, 2 May 2017 11:47:01 +0100
Subject: [PATCH] Issue #2863778 by BR0kEN, dawehner, l0ke, Wim Leers,
 alexpott, catch: Clean up \Drupal\hal\Normalizer\NormalizerBase: duplicate
 less from the parent class \Drupal\serialization\Normalizer\NormalizerBase

---
 .../hal/src/Normalizer/FieldNormalizer.php    |  4 +--
 .../hal/src/Normalizer/NormalizerBase.php     | 28 +++++--------------
 .../src/Normalizer/NormalizerBase.php         |  9 +++++-
 3 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/core/modules/hal/src/Normalizer/FieldNormalizer.php b/core/modules/hal/src/Normalizer/FieldNormalizer.php
index a4e175323ac1..167499a26f5e 100644
--- a/core/modules/hal/src/Normalizer/FieldNormalizer.php
+++ b/core/modules/hal/src/Normalizer/FieldNormalizer.php
@@ -11,9 +11,7 @@
 class FieldNormalizer extends SerializationFieldNormalizer {
 
   /**
-   * The formats that the Normalizer can handle.
-   *
-   * @var array
+   * {@inheritdoc}
    */
   protected $format = ['hal_json'];
 
diff --git a/core/modules/hal/src/Normalizer/NormalizerBase.php b/core/modules/hal/src/Normalizer/NormalizerBase.php
index 43a5a07161f5..8b18985b8b46 100644
--- a/core/modules/hal/src/Normalizer/NormalizerBase.php
+++ b/core/modules/hal/src/Normalizer/NormalizerBase.php
@@ -10,36 +10,22 @@
  */
 abstract class NormalizerBase extends SerializationNormalizerBase implements DenormalizerInterface {
 
-  /**
-   * The formats that the Normalizer can handle.
-   *
-   * @var array
-   */
-  protected $formats = ['hal_json'];
-
   /**
    * {@inheritdoc}
    */
-  public function supportsNormalization($data, $format = NULL) {
-    return in_array($format, $this->formats) && parent::supportsNormalization($data, $format);
-  }
+  protected $format = ['hal_json'];
 
   /**
    * {@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));
-      }
+  protected function checkFormat($format = NULL) {
+    if (isset($this->formats)) {
+      @trigger_error('::formats is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use ::$format instead. See https://www.drupal.org/node/2868275', E_USER_DEPRECATED);
+
+      $this->format = $this->formats;
     }
 
-    return FALSE;
+    return parent::checkFormat($format);
   }
 
 }
diff --git a/core/modules/serialization/src/Normalizer/NormalizerBase.php b/core/modules/serialization/src/Normalizer/NormalizerBase.php
index 90d9b7525816..7916a9092af2 100644
--- a/core/modules/serialization/src/Normalizer/NormalizerBase.php
+++ b/core/modules/serialization/src/Normalizer/NormalizerBase.php
@@ -17,6 +17,13 @@ abstract class NormalizerBase extends SerializerAwareNormalizer implements Norma
    */
   protected $supportedInterfaceOrClass;
 
+  /**
+   * List of formats which supports (de-)normalization.
+   *
+   * @var string|string[]
+   */
+  protected $format;
+
   /**
    * {@inheritdoc}
    */
@@ -71,7 +78,7 @@ protected function checkFormat($format = NULL) {
       return TRUE;
     }
 
-    return in_array($format, (array) $this->format);
+    return in_array($format, (array) $this->format, TRUE);
   }
 
 }
-- 
GitLab