comparison vendor/symfony/serializer/Normalizer/GetSetMethodNormalizer.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
32 * @author Nils Adermann <naderman@naderman.de> 32 * @author Nils Adermann <naderman@naderman.de>
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 = [];
38 private $cache = array(); 38 private $cache = [];
39 39
40 /** 40 /**
41 * {@inheritdoc} 41 * {@inheritdoc}
42 */ 42 */
43 public function supportsNormalization($data, $format = null) 43 public function supportsNormalization($data, $format = null)
94 } 94 }
95 95
96 /** 96 /**
97 * {@inheritdoc} 97 * {@inheritdoc}
98 */ 98 */
99 protected function extractAttributes($object, $format = null, array $context = array()) 99 protected function extractAttributes($object, $format = null, array $context = [])
100 { 100 {
101 $reflectionObject = new \ReflectionObject($object); 101 $reflectionObject = new \ReflectionObject($object);
102 $reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC); 102 $reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC);
103 103
104 $attributes = array(); 104 $attributes = [];
105 foreach ($reflectionMethods as $method) { 105 foreach ($reflectionMethods as $method) {
106 if (!$this->isGetMethod($method)) { 106 if (!$this->isGetMethod($method)) {
107 continue; 107 continue;
108 } 108 }
109 109
118 } 118 }
119 119
120 /** 120 /**
121 * {@inheritdoc} 121 * {@inheritdoc}
122 */ 122 */
123 protected function getAttributeValue($object, $attribute, $format = null, array $context = array()) 123 protected function getAttributeValue($object, $attribute, $format = null, array $context = [])
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([$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([$object, $isser])) {
134 return $object->$isser(); 134 return $object->$isser();
135 } 135 }
136 136
137 $haser = 'has'.$ucfirsted; 137 $haser = 'has'.$ucfirsted;
138 if (\is_callable(array($object, $haser))) { 138 if (\is_callable([$object, $haser])) {
139 return $object->$haser(); 139 return $object->$haser();
140 } 140 }
141 } 141 }
142 142
143 /** 143 /**
144 * {@inheritdoc} 144 * {@inheritdoc}
145 */ 145 */
146 protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array()) 146 protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = [])
147 { 147 {
148 $setter = 'set'.ucfirst($attribute); 148 $setter = 'set'.ucfirst($attribute);
149 $key = \get_class($object).':'.$setter; 149 $key = \get_class($object).':'.$setter;
150 150
151 if (!isset(self::$setterAccessibleCache[$key])) { 151 if (!isset(self::$setterAccessibleCache[$key])) {
152 self::$setterAccessibleCache[$key] = \is_callable(array($object, $setter)) && !(new \ReflectionMethod($object, $setter))->isStatic(); 152 self::$setterAccessibleCache[$key] = \is_callable([$object, $setter]) && !(new \ReflectionMethod($object, $setter))->isStatic();
153 } 153 }
154 154
155 if (self::$setterAccessibleCache[$key]) { 155 if (self::$setterAccessibleCache[$key]) {
156 $object->$setter($value); 156 $object->$setter($value);
157 } 157 }