Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / serializer / Normalizer / GetSetMethodNormalizer.php
index 2a15d46d63b103ec18ae0fb95010fef01b4b9342..6eec9dd4d9bd06059dcf2b5b070ca81c773d20c7 100644 (file)
@@ -35,13 +35,14 @@ namespace Symfony\Component\Serializer\Normalizer;
 class GetSetMethodNormalizer extends AbstractObjectNormalizer
 {
     private static $setterAccessibleCache = array();
+    private $cache = array();
 
     /**
      * {@inheritdoc}
      */
     public function supportsNormalization($data, $format = null)
     {
-        return parent::supportsNormalization($data, $format) && $this->supports(get_class($data));
+        return parent::supportsNormalization($data, $format) && (isset($this->cache[$type = \get_class($data)]) ? $this->cache[$type] : $this->cache[$type] = $this->supports($type));
     }
 
     /**
@@ -49,7 +50,7 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
      */
     public function supportsDenormalization($data, $type, $format = null)
     {
-        return parent::supportsDenormalization($data, $type, $format) && $this->supports($type);
+        return parent::supportsDenormalization($data, $type, $format) && (isset($this->cache[$type]) ? $this->cache[$type] : $this->cache[$type] = $this->supports($type));
     }
 
     /**
@@ -75,19 +76,18 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
     /**
      * Checks if a method's name is get.* or is.*, and can be called without parameters.
      *
-     * @param \ReflectionMethod $method the method to check
-     *
      * @return bool whether the method is a getter or boolean getter
      */
     private function isGetMethod(\ReflectionMethod $method)
     {
-        $methodLength = strlen($method->name);
+        $methodLength = \strlen($method->name);
 
         return
             !$method->isStatic() &&
             (
                 ((0 === strpos($method->name, 'get') && 3 < $methodLength) ||
-                (0 === strpos($method->name, 'is') && 2 < $methodLength)) &&
+                (0 === strpos($method->name, 'is') && 2 < $methodLength) ||
+                (0 === strpos($method->name, 'has') && 3 < $methodLength)) &&
                 0 === $method->getNumberOfRequiredParameters()
             )
         ;
@@ -125,14 +125,19 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
         $ucfirsted = ucfirst($attribute);
 
         $getter = 'get'.$ucfirsted;
-        if (is_callable(array($object, $getter))) {
+        if (\is_callable(array($object, $getter))) {
             return $object->$getter();
         }
 
         $isser = 'is'.$ucfirsted;
-        if (is_callable(array($object, $isser))) {
+        if (\is_callable(array($object, $isser))) {
             return $object->$isser();
         }
+
+        $haser = 'has'.$ucfirsted;
+        if (\is_callable(array($object, $haser))) {
+            return $object->$haser();
+        }
     }
 
     /**
@@ -141,10 +146,10 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
     protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array())
     {
         $setter = 'set'.ucfirst($attribute);
-        $key = get_class($object).':'.$setter;
+        $key = \get_class($object).':'.$setter;
 
         if (!isset(self::$setterAccessibleCache[$key])) {
-            self::$setterAccessibleCache[$key] = is_callable(array($object, $setter)) && !(new \ReflectionMethod($object, $setter))->isStatic();
+            self::$setterAccessibleCache[$key] = \is_callable(array($object, $setter)) && !(new \ReflectionMethod($object, $setter))->isStatic();
         }
 
         if (self::$setterAccessibleCache[$key]) {