Exemplo n.º 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 = [];
     foreach ($class->fieldMappings as $fieldName => $mapping) {
         if (isset($mapping['notSaved'])) {
             continue;
         }
         $rp = $class->reflFields[$fieldName];
         $value = $rp->getValue($document);
         if (isset($mapping['association']) && $mapping['association'] & ClassMetadata::TO_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());
             $rp->setValue($document, $coll);
             $value = $coll;
         }
         $actualData[$fieldName] = $value;
     }
     return $actualData;
 }