Mercurial > hg > isophonics-drupal-site
diff vendor/symfony/serializer/Normalizer/GetSetMethodNormalizer.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/GetSetMethodNormalizer.php Mon Apr 23 09:33:26 2018 +0100 +++ b/vendor/symfony/serializer/Normalizer/GetSetMethodNormalizer.php Mon Apr 23 09:46:53 2018 +0100 @@ -35,13 +35,14 @@ 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 @@ */ 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 @@ /** * 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 @@ $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 @@ 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]) {