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 normalize($input) { $entity = $input; $metadata = $this->getClassMetadata(); $array = array(); foreach ($metadata->getFieldNames() as $field) { $array[$field] = $metadata->getFieldValue($entity, $field); } foreach ($metadata->getAssociationNames() as $field) { $value = $metadata->getFieldValue($entity, $field); if ($metadata->isCollectionValuedAssociation($field)) { $normalizer = new Doctrine2EntityBatchNormalizer($this->getEntityManager(), $this->getEntityManager()->getClassMetadata($metadata->getAssociationTargetClass($field))); } else { $normalizer = new Doctrine2EntityNormalizer($this->getEntityManager(), $this->getEntityManager()->getClassMetadata($metadata->getAssociationTargetClass($field))); } $array[$field] = $normalizer->normalize($value); } return $array; }