Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ObjectNormalizer.php

function ObjectNormalizer::isAllowedAttribute

Overrides AbstractNormalizer::isAllowedAttribute

1 call to ObjectNormalizer::isAllowedAttribute()
ObjectNormalizer::extractAttributes in vendor/symfony/serializer/Normalizer/ObjectNormalizer.php
Extracts attributes to normalize from the class of the given object, format and context.

File

vendor/symfony/serializer/Normalizer/ObjectNormalizer.php, line 176

Class

ObjectNormalizer
Converts between objects and arrays using the PropertyAccess component.

Namespace

Symfony\Component\Serializer\Normalizer

Code

protected function isAllowedAttribute($classOrObject, string $attribute, ?string $format = null, array $context = []) : bool {
    if (!parent::isAllowedAttribute($classOrObject, $attribute, $format, $context)) {
        return false;
    }
    $class = \is_object($classOrObject) ? $classOrObject::class : $classOrObject;
    if ($context['_read_attributes'] ?? true) {
        if (!isset(self::$isReadableCache[$class . $attribute])) {
            self::$isReadableCache[$class . $attribute] = $this->propertyInfoExtractor
                ->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute) || \is_object($classOrObject) && $this->propertyAccessor
                ->isReadable($classOrObject, $attribute);
        }
        return self::$isReadableCache[$class . $attribute];
    }
    if (!isset(self::$isWritableCache[$class . $attribute])) {
        if (str_contains($attribute, '.')) {
            self::$isWritableCache[$class . $attribute] = true;
        }
        else {
            self::$isWritableCache[$class . $attribute] = $this->propertyInfoExtractor
                ->isWritable($class, $attribute) || ($writeInfo = $this->writeInfoExtractor
                ->getWriteInfo($class, $attribute)) && PropertyWriteInfo::TYPE_NONE !== $writeInfo->getType();
        }
    }
    return self::$isWritableCache[$class . $attribute];
}
RSS feed
Powered by Drupal