public function GetSetMethodNormalizer::denormalize in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony/serializer/Normalizer/GetSetMethodNormalizer.php \Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer::denormalize()
Throws
Overrides DenormalizerInterface::denormalize
File
- vendor/
symfony/ serializer/ Normalizer/ GetSetMethodNormalizer.php, line 97
Class
- GetSetMethodNormalizer
- Converts between objects with getter and setter methods and arrays.
Namespace
Symfony\Component\Serializer\NormalizerCode
public function denormalize($data, $class, $format = null, array $context = array()) {
$allowedAttributes = $this
->getAllowedAttributes($class, $context, true);
$normalizedData = $this
->prepareForDenormalization($data);
$reflectionClass = new \ReflectionClass($class);
$object = $this
->instantiateObject($normalizedData, $class, $context, $reflectionClass, $allowedAttributes);
$classMethods = get_class_methods($object);
foreach ($normalizedData as $attribute => $value) {
if ($this->nameConverter) {
$attribute = $this->nameConverter
->denormalize($attribute);
}
$allowed = $allowedAttributes === false || in_array($attribute, $allowedAttributes);
$ignored = in_array($attribute, $this->ignoredAttributes);
if ($allowed && !$ignored) {
$setter = 'set' . ucfirst($attribute);
if (in_array($setter, $classMethods)) {
$object
->{$setter}($value);
}
}
}
return $object;
}