function PropertyNormalizer::getAttributeValue
Overrides AbstractObjectNormalizer::getAttributeValue
File
-
vendor/
symfony/ serializer/ Normalizer/ PropertyNormalizer.php, line 146
Class
- PropertyNormalizer
- Converts between objects and arrays by mapping properties.
Namespace
Symfony\Component\Serializer\NormalizerCode
protected function getAttributeValue(object $object, string $attribute, ?string $format = null, array $context = []) : mixed {
try {
$reflectionProperty = $this->getReflectionProperty($object, $attribute);
} catch (\ReflectionException) {
return null;
}
if ($reflectionProperty->hasType()) {
return $reflectionProperty->getValue($object);
}
if (!method_exists($object, '__get') && !isset($object->{$attribute})) {
$propertyValues = (array) $object;
if ($reflectionProperty->isPublic() && !\array_key_exists($reflectionProperty->name, $propertyValues) || $reflectionProperty->isProtected() && !\array_key_exists("\x00*\x00{$reflectionProperty->name}", $propertyValues) || $reflectionProperty->isPrivate() && !\array_key_exists("\x00{$reflectionProperty->class}\x00{$reflectionProperty->name}", $propertyValues)) {
throw new UninitializedPropertyException(\sprintf('The property "%s::$%s" is not initialized.', $object::class, $reflectionProperty->name));
}
}
return $reflectionProperty->getValue($object);
}