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

Breadcrumb

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

function PropertyNormalizer::isAllowedAttribute

Overrides AbstractNormalizer::isAllowedAttribute

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

File

vendor/symfony/serializer/Normalizer/PropertyNormalizer.php, line 95

Class

PropertyNormalizer
Converts between objects and arrays by mapping properties.

Namespace

Symfony\Component\Serializer\Normalizer

Code

protected function isAllowedAttribute(object|string $classOrObject, string $attribute, ?string $format = null, array $context = []) : bool {
    if (!parent::isAllowedAttribute($classOrObject, $attribute, $format, $context)) {
        return false;
    }
    try {
        $reflectionProperty = $this->getReflectionProperty($classOrObject, $attribute);
    } catch (\ReflectionException) {
        return false;
    }
    if ($reflectionProperty->isStatic()) {
        return false;
    }
    $normalizeVisibility = $context[self::NORMALIZE_VISIBILITY] ?? $this->defaultContext[self::NORMALIZE_VISIBILITY];
    if (self::NORMALIZE_PUBLIC & $normalizeVisibility && $reflectionProperty->isPublic()) {
        return true;
    }
    if (self::NORMALIZE_PROTECTED & $normalizeVisibility && $reflectionProperty->isProtected()) {
        return true;
    }
    if (self::NORMALIZE_PRIVATE & $normalizeVisibility && $reflectionProperty->isPrivate()) {
        return true;
    }
    return false;
}
RSS feed
Powered by Drupal