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

Breadcrumb

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

function GetSetMethodNormalizer::extractAttributes

Overrides AbstractObjectNormalizer::extractAttributes

File

vendor/symfony/serializer/Normalizer/GetSetMethodNormalizer.php, line 108

Class

GetSetMethodNormalizer
Converts between objects with getter and setter methods and arrays.

Namespace

Symfony\Component\Serializer\Normalizer

Code

protected function extractAttributes(object $object, ?string $format = null, array $context = []) : array {
    $reflectionObject = new \ReflectionObject($object);
    $reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC);
    $attributes = [];
    foreach ($reflectionMethods as $method) {
        if (!$this->isGetMethod($method)) {
            continue;
        }
        $attributeName = lcfirst(substr($method->name, str_starts_with($method->name, 'is') ? 2 : 3));
        if ($this->isAllowedAttribute($object, $attributeName, $format, $context)) {
            $attributes[] = $attributeName;
        }
    }
    return $attributes;
}
RSS feed
Powered by Drupal