You are here

public function ObjectNormalizer::denormalize in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/serializer/Normalizer/ObjectNormalizer.php \Symfony\Component\Serializer\Normalizer\ObjectNormalizer::denormalize()

Denormalizes data back into an object of the given class.

Parameters

mixed $data data to restore:

string $class the expected class to instantiate:

string $format format the given data was extracted from:

array $context options available to the denormalizer:

Return value

object

Overrides DenormalizerInterface::denormalize

File

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

Class

ObjectNormalizer
Converts between objects and arrays using the PropertyAccess component.

Namespace

Symfony\Component\Serializer\Normalizer

Code

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);
  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) {
      try {
        $this->propertyAccessor
          ->setValue($object, $attribute, $value);
      } catch (NoSuchPropertyException $exception) {

        // Properties not found are ignored
      }
    }
  }
  return $object;
}