/**
* Get a documents actual data, flattening all the objects to arrays.
*
* @param object $document
* @return array
*/
public function getDocumentActualData($document)
{
$class = $this->dm->getClassMetadata(get_class($document));
$actualData = array();
foreach ($class->reflFields as $name => $refProp) {
$mapping = $class->fieldMappings[$name];
$value = $refProp->getValue($document);
if (isset($mapping['file']) && !$value instanceof GridFSFile) {
$value = new GridFSFile($value);
$class->reflFields[$name]->setValue($document, $value);
$actualData[$name] = $value;
} elseif (($class->isCollectionValuedReference($name) || $class->isCollectionValuedEmbed($name)) && $value !== null && !$value instanceof PersistentCollection) {
// If $actualData[$name] is not a Collection then use an ArrayCollection.
if (!$value instanceof Collection) {
$value = new ArrayCollection($value);
}
// Inject PersistentCollection
$coll = new PersistentCollection($value, $this->dm, $this, $this->cmd);
$coll->setOwner($document, $mapping);
$coll->setDirty(!$value->isEmpty());
$class->reflFields[$name]->setValue($document, $coll);
$actualData[$name] = $coll;
} else {
if (!$class->isIdentifier($name) || $class->isIdGeneratorNone()) {
$actualData[$name] = $value;
}
}
}
return $actualData;
}