Beispiel #1
0
 /**
  * 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];
         // skip not saved fields
         if (isset($mapping['notSaved']) && $mapping['notSaved'] === true) {
             continue;
         }
         $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 (isset($mapping['association']) && $mapping['type'] === 'many' && $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);
             $coll->setOwner($document, $mapping);
             $coll->setDirty(!$value->isEmpty());
             $class->reflFields[$name]->setValue($document, $coll);
             $actualData[$name] = $coll;
         } else {
             $actualData[$name] = $value;
         }
     }
     return $actualData;
 }