|
35 | 35 | class ObjectNormalizer extends AbstractObjectNormalizer
|
36 | 36 | {
|
37 | 37 | private static $reflectionCache = [];
|
| 38 | + private static $isReadableCache = []; |
| 39 | + private static $isWritableCache = []; |
38 | 40 |
|
39 | 41 | protected $propertyAccessor;
|
40 | 42 | protected $propertyInfoExtractor;
|
@@ -185,21 +187,23 @@ protected function isAllowedAttribute($classOrObject, string $attribute, ?string
|
185 | 187 | if (!parent::isAllowedAttribute($classOrObject, $attribute, $format, $context)) {
|
186 | 188 | return false;
|
187 | 189 | }
|
| 190 | + |
188 | 191 | $class = \is_object($classOrObject) ? \get_class($classOrObject) : $classOrObject;
|
189 | 192 |
|
190 | 193 | if ($context['_read_attributes'] ?? true) {
|
191 |
| - return $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute); |
192 |
| - } |
| 194 | + if (!isset(self::$isReadableCache[$class.$attribute])) { |
| 195 | + self::$isReadableCache[$class.$attribute] = $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute); |
| 196 | + } |
193 | 197 |
|
194 |
| - if ($this->propertyInfoExtractor->isWritable($class, $attribute)) { |
195 |
| - return true; |
| 198 | + return self::$isReadableCache[$class.$attribute]; |
196 | 199 | }
|
197 | 200 |
|
198 |
| - if (($writeInfo = $this->writeInfoExtractor->getWriteInfo($class, $attribute)) && PropertyWriteInfo::TYPE_NONE !== $writeInfo->getType()) { |
199 |
| - return true; |
| 201 | + if (!isset(self::$isWritableCache[$class.$attribute])) { |
| 202 | + self::$isWritableCache[$class.$attribute] = $this->propertyInfoExtractor->isWritable($class, $attribute) |
| 203 | + || (($writeInfo = $this->writeInfoExtractor->getWriteInfo($class, $attribute)) && PropertyWriteInfo::TYPE_NONE !== $writeInfo->getType()); |
200 | 204 | }
|
201 | 205 |
|
202 |
| - return false; |
| 206 | + return self::$isWritableCache[$class.$attribute]; |
203 | 207 | }
|
204 | 208 |
|
205 | 209 | private function hasAttributeAccessorMethod(string $class, string $attribute): bool
|
|
0 commit comments