Пример #1
0
 /**
  * {@inheritDoc}
  *
  * @param mixed $data
  * @param object $object
  *
  * @return object
  */
 public function denormalize(array $data, $object)
 {
     $className = ObjectHelper::getFullClassName($object);
     $metadata = $this->metadataFactory->getMetadataForClass($className);
     $unserializedProperties = 0;
     foreach ($metadata->getProperties() as $property) {
         if ($this->propertySkipper->shouldSkip($property)) {
             if ($this->isMediumStrictUnserializeMode() && array_key_exists($property->getSerializedName(), $data)) {
                 throw new InvalidArgumentException(sprintf('%s extra field', $property->getSerializedName()));
             }
             continue;
         }
         if (!array_key_exists($property->getSerializedName(), $data)) {
             if ($this->isStrictUnserializeMode()) {
                 throw new InvalidArgumentException(sprintf('%s field is lost', $property->getSerializedName()));
             }
             continue;
         }
         $value = $this->dataProcessor->denormalizeProcess($this, $data[$property->getSerializedName()], $property, $object);
         ObjectHelper::involve($object, $property, $value);
         $unserializedProperties++;
     }
     if ($this->isMediumStrictUnserializeMode() && $unserializedProperties !== count($data)) {
         throw new InvalidArgumentException('Wrong number of fields in the deserialized data');
     }
     return $object;
 }
 /**
  * @param array $value
  * @param PropertyMetadata $property
  * @param mixed $object
  * @return array
  */
 public function denormalize($value, $property, $object)
 {
     $result = array();
     $itemProperty = $this->makeItemProperty($property);
     $existsData = ObjectHelper::expose($object, $property);
     $inner = false;
     foreach ($value as $subKey => $subValue) {
         $tmpObject = $object;
         if (isset($existsData[$subKey]) && is_object($existsData[$subKey])) {
             $tmpObject = $existsData[$subKey];
             $inner = true;
         }
         $result[$subKey] = $this->processor->denormalizeProcess($this->normalizer, $subValue, $itemProperty, $tmpObject, $inner);
         unset($tmpObject);
     }
     return $result;
 }