diff vendor/symfony/serializer/Normalizer/CustomNormalizer.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
line wrap: on
line diff
--- a/vendor/symfony/serializer/Normalizer/CustomNormalizer.php	Mon Apr 23 09:33:26 2018 +0100
+++ b/vendor/symfony/serializer/Normalizer/CustomNormalizer.php	Mon Apr 23 09:46:53 2018 +0100
@@ -19,8 +19,11 @@
  */
 class CustomNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface
 {
+    use ObjectToPopulateTrait;
     use SerializerAwareTrait;
 
+    private $cache = array();
+
     /**
      * {@inheritdoc}
      */
@@ -34,7 +37,7 @@
      */
     public function denormalize($data, $class, $format = null, array $context = array())
     {
-        $object = new $class();
+        $object = $this->extractObjectToPopulate($class, $context) ?: new $class();
         $object->denormalize($this->serializer, $data, $format, $context);
 
         return $object;
@@ -54,7 +57,7 @@
     }
 
     /**
-     * Checks if the given class implements the NormalizableInterface.
+     * Checks if the given class implements the DenormalizableInterface.
      *
      * @param mixed  $data   Data to denormalize from
      * @param string $type   The class to which the data should be denormalized
@@ -64,10 +67,14 @@
      */
     public function supportsDenormalization($data, $type, $format = null)
     {
-        if (!class_exists($type)) {
-            return false;
+        if (isset($this->cache[$type])) {
+            return $this->cache[$type];
         }
 
-        return is_subclass_of($type, 'Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
+        if (!class_exists($type)) {
+            return $this->cache[$type] = false;
+        }
+
+        return $this->cache[$type] = is_subclass_of($type, 'Symfony\Component\Serializer\Normalizer\DenormalizableInterface');
     }
 }