public function denormalize(array $input, $context = null) { $collection = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($array as $key => $value) { $collection->set($key, parent::normalize($input)); } return new PersistentCollection($this->getEntityManager(), $this->getClassMetadata()->getName(), $collection); }
public function denormalize(array $input, $context = null) { $metadata = $this->getClassMetadata(); $class = $metadata->getName(); if (!is_null($context) && is_object($context) && $context instanceof $class) { $entity = $context; } if (!is_null($context) && is_array($context)) { $entity = $this->denormalize($context); } else { $entity = new $class(); } foreach ($metadata->getFieldNames() as $field) { if (isset($input[$field])) { $metadata->setFieldValue($entity, $field, $input[$field]); } } foreach ($metadata->getAssociationNames() as $field) { if (isset($input[$field]) && $input($array[$field])) { if ($metadata->isCollectionValuedAssociation($field)) { $normalizer = new Doctrine2EntityBatchNormalizer($this->getEntityManager(), $this->getEntityManager()->getMetadataFactory()->getMetadataFor($metadata->getAssociationTargetClass($field))); } else { $normalizer = new Doctrine2EntityNormalizer($this->getEntityManager(), $this->getEntityManager()->getMetadataFactory()->getMetadataFor($metadata->getAssociationTargetClass($field))); } $value = $normalizer->denormalize($input[$field]); $metadata->setFieldValue($entity, $field, $value); } } return $entity; }