Mercurial > hg > isophonics-drupal-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
33 * @author Kévin Dunglas <dunglas@gmail.com> | 33 * @author Kévin Dunglas <dunglas@gmail.com> |
34 */ | 34 */ |
35 class GetSetMethodNormalizer extends AbstractObjectNormalizer | 35 class GetSetMethodNormalizer extends AbstractObjectNormalizer |
36 { | 36 { |
37 private static $setterAccessibleCache = array(); | 37 private static $setterAccessibleCache = array(); |
38 private $cache = array(); | |
38 | 39 |
39 /** | 40 /** |
40 * {@inheritdoc} | 41 * {@inheritdoc} |
41 */ | 42 */ |
42 public function supportsNormalization($data, $format = null) | 43 public function supportsNormalization($data, $format = null) |
43 { | 44 { |
44 return parent::supportsNormalization($data, $format) && $this->supports(get_class($data)); | 45 return parent::supportsNormalization($data, $format) && (isset($this->cache[$type = \get_class($data)]) ? $this->cache[$type] : $this->cache[$type] = $this->supports($type)); |
45 } | 46 } |
46 | 47 |
47 /** | 48 /** |
48 * {@inheritdoc} | 49 * {@inheritdoc} |
49 */ | 50 */ |
50 public function supportsDenormalization($data, $type, $format = null) | 51 public function supportsDenormalization($data, $type, $format = null) |
51 { | 52 { |
52 return parent::supportsDenormalization($data, $type, $format) && $this->supports($type); | 53 return parent::supportsDenormalization($data, $type, $format) && (isset($this->cache[$type]) ? $this->cache[$type] : $this->cache[$type] = $this->supports($type)); |
53 } | 54 } |
54 | 55 |
55 /** | 56 /** |
56 * Checks if the given class has any get{Property} method. | 57 * Checks if the given class has any get{Property} method. |
57 * | 58 * |
73 } | 74 } |
74 | 75 |
75 /** | 76 /** |
76 * Checks if a method's name is get.* or is.*, and can be called without parameters. | 77 * Checks if a method's name is get.* or is.*, and can be called without parameters. |
77 * | 78 * |
78 * @param \ReflectionMethod $method the method to check | |
79 * | |
80 * @return bool whether the method is a getter or boolean getter | 79 * @return bool whether the method is a getter or boolean getter |
81 */ | 80 */ |
82 private function isGetMethod(\ReflectionMethod $method) | 81 private function isGetMethod(\ReflectionMethod $method) |
83 { | 82 { |
84 $methodLength = strlen($method->name); | 83 $methodLength = \strlen($method->name); |
85 | 84 |
86 return | 85 return |
87 !$method->isStatic() && | 86 !$method->isStatic() && |
88 ( | 87 ( |
89 ((0 === strpos($method->name, 'get') && 3 < $methodLength) || | 88 ((0 === strpos($method->name, 'get') && 3 < $methodLength) || |
90 (0 === strpos($method->name, 'is') && 2 < $methodLength)) && | 89 (0 === strpos($method->name, 'is') && 2 < $methodLength) || |
90 (0 === strpos($method->name, 'has') && 3 < $methodLength)) && | |
91 0 === $method->getNumberOfRequiredParameters() | 91 0 === $method->getNumberOfRequiredParameters() |
92 ) | 92 ) |
93 ; | 93 ; |
94 } | 94 } |
95 | 95 |
123 protected function getAttributeValue($object, $attribute, $format = null, array $context = array()) | 123 protected function getAttributeValue($object, $attribute, $format = null, array $context = array()) |
124 { | 124 { |
125 $ucfirsted = ucfirst($attribute); | 125 $ucfirsted = ucfirst($attribute); |
126 | 126 |
127 $getter = 'get'.$ucfirsted; | 127 $getter = 'get'.$ucfirsted; |
128 if (is_callable(array($object, $getter))) { | 128 if (\is_callable(array($object, $getter))) { |
129 return $object->$getter(); | 129 return $object->$getter(); |
130 } | 130 } |
131 | 131 |
132 $isser = 'is'.$ucfirsted; | 132 $isser = 'is'.$ucfirsted; |
133 if (is_callable(array($object, $isser))) { | 133 if (\is_callable(array($object, $isser))) { |
134 return $object->$isser(); | 134 return $object->$isser(); |
135 } | |
136 | |
137 $haser = 'has'.$ucfirsted; | |
138 if (\is_callable(array($object, $haser))) { | |
139 return $object->$haser(); | |
135 } | 140 } |
136 } | 141 } |
137 | 142 |
138 /** | 143 /** |
139 * {@inheritdoc} | 144 * {@inheritdoc} |
140 */ | 145 */ |
141 protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array()) | 146 protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array()) |
142 { | 147 { |
143 $setter = 'set'.ucfirst($attribute); | 148 $setter = 'set'.ucfirst($attribute); |
144 $key = get_class($object).':'.$setter; | 149 $key = \get_class($object).':'.$setter; |
145 | 150 |
146 if (!isset(self::$setterAccessibleCache[$key])) { | 151 if (!isset(self::$setterAccessibleCache[$key])) { |
147 self::$setterAccessibleCache[$key] = is_callable(array($object, $setter)) && !(new \ReflectionMethod($object, $setter))->isStatic(); | 152 self::$setterAccessibleCache[$key] = \is_callable(array($object, $setter)) && !(new \ReflectionMethod($object, $setter))->isStatic(); |
148 } | 153 } |
149 | 154 |
150 if (self::$setterAccessibleCache[$key]) { | 155 if (self::$setterAccessibleCache[$key]) { |
151 $object->$setter($value); | 156 $object->$setter($value); |
152 } | 157 } |