Get a documents actual data, flattening all the objects to arrays.

@param object $document

@return array
760458
public function getDocumentActualData($document)
    {
        $class      = $this->dm->getClassMetadata(get_class($document));
        $actualData = [];

        foreach ($class->propertyMetadata as $name => $mapping) {
            // skip not saved attributes
            if ($mapping->notSaved) {
                continue;
            }

            $value = $mapping->getValue($document);

            if ($mapping->isMany() && $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());
                $mapping->setValue($document, $coll);
                $actualData[$name] = $coll;
            } else {
                $actualData[$name] = $value;
            }
        }

        return $actualData;
    }
1218740
public function setDocumentData(array $document)
    {
        $this->set('__date__', new \MongoDate);
        $this->set('__documentId__', $document['_id']);
        
        unset($document['_id']);
        
        $this->merge($document);
        
        
        return $this;
    }
952484
public function toArray()
    {
        $document = [];

        if (! empty($this->links)) {
            $document['links'] = $this->links;
        }

        if (! empty($this->data)) {
            $document['data'] = $this->data->toArray();

            $resources = $this->getIncluded($this->data);

            if (count($resources)) {
                $document['included'] = array_map(function (Resource $resource) {
                    return $resource->toArray();
                }, $resources);
            }
        }

        if (! empty($this->meta)) {
            $document['meta'] = $this->meta;
        }

        if (! empty($this->errors)) {
            $document['errors'] = $this->errors;
        }

        if (! empty($this->jsonapi)) {
            $document['jsonapi'] = $this->jsonapi;
        }

        return $document;
    }
902717
static function getDocumentMap($document){
        // TODO: hadi 1396-07: It is better to move this function to Collection_Document class
        $attr = new Collection_Attribute();
        $map = $attr->getList(
            array(
                'filter' => 'document=' . $document->id
            ));
        $result = array();
        $iterator = $map->getIterator();
        while ($iterator->valid()) {
            $attr = $iterator->current();
            $result[$attr->key] = $attr->value;
            $iterator->next();
        }
        
        $result['id'] = $document->id;
        $result['collection'] = $document->collection;
        return $result;
    }
1222802
private function getQueryForDocument(object $document) : array
    {
        $id = $this->uow->getDocumentIdentifier($document);
        $id = $this->class->getDatabaseIdentifierValue($id);

        $shardKeyQueryPart = $this->getShardKeyQuery($document);
        return array_merge(['_id' => $id], $shardKeyQueryPart);
    }
461539
public function documentToEntity($document, string $entityClassName)
    {
        if (!$this->annotationParser->isEntityClass($entityClassName)) {
            return $document;
        }

        try {
            $reflectClass = new \ReflectionClass($entityClassName);
        } catch (\Exception $exception) {
            return $document;
        }

        $entity = new $entityClassName();

        foreach ($reflectClass->getProperties() as $documentProperty) {
            if ($documentProperty->isStatic()) {
                continue;
            }

            $annotation = $this->annotationParser->getPropertyAnnotation($documentProperty);
            if (null === $annotation) {
                continue;
            }

            $propertyName = $annotation->name ?? $documentProperty->getName();
            if ($annotation->id) {
                $propertyName = '_id';
            }
            $propertyValue = $document->{$propertyName} ?? null;
            $fieldValue = $this->propertyToField($propertyValue, $annotation);

            $documentProperty->setAccessible(true);
            $documentProperty->setValue($entity, $fieldValue);
        }

        return $entity;
    }
697516
private function getDocumentActualData(ClassMetadata $class, $document)
    {
        $actualData = [];
        foreach ($class->reflFields as $fieldName => $reflProperty) {
            // do not set the version info fields if they have values, they are not to be managed by the user in write scenarios.
            if ($fieldName === $class->versionNameField
                || $fieldName === $class->versionCreatedField
            ) {
                continue;
            }
            $value = $reflProperty->getValue($document);
            $actualData[$fieldName] = $value;
        }

        return $actualData;
    }
25566
protected function getDocumentBody( array $document )
    {
        if ( strpos( $document['Content-Type'], 'application/json' ) === 0 )
        {
            $source = json_decode( $document['body'], true );
            unset( $source['_rev'] );
            return json_encode( $source );
        }

        if ( is_array( $document['body'] ) )
        {
            $main   = array_shift( $document['body'] );
            $source = json_decode( $main['body'], true );
            unset( $source['_rev'] );

            $source['_attachments'] = array();
            foreach ( $document['body'] as $attachment )
            {
                $source['_attachments'][$attachment['Content-ID']] = array(
                    'content_type' => $attachment['Content-Type'],
                    'data'         => base64_encode( $attachment['body'] ),
                );
            }

            return json_encode( $source );
        }

        throw new phpillowMultipartParserException( "Invalid document: " . var_export( $document, true ) );
    }
1207796
public function getDocument($pathName = '')
    {
        if ($pathName === '') {
            $pathName = 'index';
        }

        if (! isset($this->documents[ $pathName ])) {
            $path = Path::join($this->path, $this->ref, $pathName . '.md');

            $this->documents[ $pathName ] = $this->container->make(Document::class, [
                'factory'  => $this->factory,
                'project'  => $this,
                'path'     => $path,
                'pathName' => $pathName
            ]);
            //new Document($this->factory, $this, $this->files, $path, $pathName);

            $this->runHook('project:document', [ $this->documents[ $pathName ] ]);
        }


        return $this->documents[ $pathName ];
    }
268182
public function getParent($document)
    {
        $parentNode = $this->getNode($document)->getParent();

        if (!$parentNode) {
            return;
        }

        return $this->proxyFactory->createProxyForNode($document, $parentNode);
    }
1097386
private function getPropertyData($document, LegacyProperty $property)
    {
        return $document->getStructure()->getContentViewProperty($property->getName())->getValue();
    }
598401
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;
    }
1044796
public static function document($doc)
    {
        $type = 1;
        $valid = self::cpf($doc);
        if ($valid == false) {
            $type = 2;
            $valid = self::cnpj($doc);
        }
        if ($valid == false) {
            return false;
        }
        return ['type' => $type, 'valid' => $valid];
    }
1103067
public function toArray($object)
    {
        $this->assertObjectInstance($object);

        return array_map(
            function (Field $field) use ($object) {
                return $field->get($object);
            },
            $this->getFields()
        );
    }
18621
protected function getData() {

        $sql = ['SELECT document FROM '.$this->collection->name];

        if ($this->criteria) {

            $sql[] = 'WHERE document_criteria("'.$this->criteria.'", document)';
        }

        if ($this->sort) {

            $orders = [];

            foreach ($this->sort as $field => $direction) {
                $orders[] = 'document_key("'.$field.'", document) '.($direction==-1 ? 'DESC':'ASC');
            }

            $sql[] = 'ORDER BY '.\implode(',', $orders);
        }

        if ($this->limit) {
            $sql[] = 'LIMIT '.$this->limit;

            if ($this->skip) { $sql[] = 'OFFSET '.$this->skip; }
        }

        $sql = implode(' ', $sql);

        $stmt      = $this->collection->database->connection->query($sql);
        $result    = $stmt->fetchAll( \PDO::FETCH_ASSOC);
        $documents = [];

        if (!$this->projection) {

            foreach ($result as &$doc) {
                $documents[] = \json_decode($doc['document'], true);
            }

        } else {

            $exclude = [];
            $include = [];

            foreach ($this->projection as $key => $value) {

                if ($value) {
                    $include[$key] = 1;
                } else {
                    $exclude[$key] = 1;
                }
            }

            foreach ($result as &$doc) {

                $item = \json_decode($doc['document'], true);
                $id   = $item['_id'];

                if ($exclude) {
                    $item = \array_diff_key($item, $exclude);
                }

                if ($include) {
                    $item = array_key_intersect($item, $include);
                }

                if (!isset($exclude['_id'])) {
                    $item['_id'] = $id;
                }

                $documents[] = $item;
            }
        }

        return $documents;
    }
743022
public 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;
    }
797495
public static function getDocumentCompany($document)
    {
        return $document->getDataValue('firma') ? \FlexiPeeHP\FlexiBeeRO::uncode(
                $document->getDataValue('firma')) : null;
    }