Skip to content

Commit

Permalink
Merge branch '7.0' into 7.1
Browse files Browse the repository at this point in the history
* 7.0:
  Update PR template
  Review Indonesian (id) translation
  [Security] reviewed Latvian translation of key 20
  [VarExporter] Fix exporting default values involving global constants
  review: RU translation
  [Security] reviewed Polish translation of key 20
  Reviewing translations for Japanese.
  [Serializer] Cache readability/writability computation
  Update security.fr.xlf
  • Loading branch information
derrabus committed May 21, 2024
2 parents f43a533 + e205ae5 commit 972eb05
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Normalizer/ObjectNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
final class ObjectNormalizer extends AbstractObjectNormalizer
{
private static $reflectionCache = [];
private static $isReadableCache = [];
private static $isWritableCache = [];

protected PropertyAccessorInterface $propertyAccessor;
protected $propertyInfoExtractor;
Expand Down Expand Up @@ -170,21 +172,23 @@ protected function isAllowedAttribute($classOrObject, string $attribute, ?string
if (!parent::isAllowedAttribute($classOrObject, $attribute, $format, $context)) {
return false;
}

$class = \is_object($classOrObject) ? \get_class($classOrObject) : $classOrObject;

if ($context['_read_attributes'] ?? true) {
return $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute);
}
if (!isset(self::$isReadableCache[$class.$attribute])) {
self::$isReadableCache[$class.$attribute] = $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute);
}

if ($this->propertyInfoExtractor->isWritable($class, $attribute)) {
return true;
return self::$isReadableCache[$class.$attribute];
}

if (($writeInfo = $this->writeInfoExtractor->getWriteInfo($class, $attribute)) && PropertyWriteInfo::TYPE_NONE !== $writeInfo->getType()) {
return true;
if (!isset(self::$isWritableCache[$class.$attribute])) {
self::$isWritableCache[$class.$attribute] = $this->propertyInfoExtractor->isWritable($class, $attribute)
|| (($writeInfo = $this->writeInfoExtractor->getWriteInfo($class, $attribute)) && PropertyWriteInfo::TYPE_NONE !== $writeInfo->getType());
}

return false;
return self::$isWritableCache[$class.$attribute];
}

private function hasAttributeAccessorMethod(string $class, string $attribute): bool
Expand Down

0 comments on commit 972eb05

Please sign in to comment.