Doctrine\ODM\MongoDB\UnitOfWork::getDocumentActualData PHP Method

getDocumentActualData() public method

Get a documents actual data, flattening all the objects to arrays.
public getDocumentActualData ( object $document ) : array
$document object
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 PersistentCollectionInterface) {
                // If $actualData[$name] is not a Collection then use an ArrayCollection.
                if (!$value instanceof Collection) {
                    $value = new ArrayCollection($value);
                }
                // Inject PersistentCollection
                $coll = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $mapping, $value);
                $coll->setOwner($document, $mapping);
                $coll->setDirty(!$value->isEmpty());
                $class->reflFields[$name]->setValue($document, $coll);
                $actualData[$name] = $coll;
            } else {
                $actualData[$name] = $value;
            }
        }
        return $actualData;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @param object $document
  *
  * @return array
  * @throws MongoDBException
  */
 private function getShardKeyQuery($document)
 {
     if (!$this->class->isSharded()) {
         return array();
     }
     $shardKey = $this->class->getShardKey();
     $keys = array_keys($shardKey['keys']);
     $data = $this->uow->getDocumentActualData($document);
     $shardKeyQueryPart = array();
     foreach ($keys as $key) {
         $mapping = $this->class->getFieldMappingByDbFieldName($key);
         $this->guardMissingShardKey($document, $key, $data);
         $value = Type::getType($mapping['type'])->convertToDatabaseValue($data[$mapping['fieldName']]);
         $shardKeyQueryPart[$key] = $value;
     }
     return $shardKeyQueryPart;
 }
All Usage Examples Of Doctrine\ODM\MongoDB\UnitOfWork::getDocumentActualData
UnitOfWork