@param BSONDocument $document

@return array
510787
private function buildAggregateAsObject($document)
    {
        $returnObject = [];

        foreach ($document as $event) {
            $returnObject[] = new Event(
                new AggregateUuid($event->uuid),
                $event->type,
                unserialize($event->body),
                $event->version,
                $event->occurred_on
            );
        }

        return $returnObject;
    }
499103
public function serialize(Document $document)
    {
        return [
            'id' => $document->getUuid(),
            'type' => $document->getType(),
            'data' => Document::DOCUMENT_TYPE_RESOURCE === $document->getType() ?
                $this->resourceSerializer->serialize($document->getData()) :
                $document->getData(),
            'drop' => $document->getDrop()->getUuid(),
            'user' => $document->getUser() ? $this->userSerializer->serialize($document->getUser()) : null,
            'dropDate' => $document->getDropDate() ? $document->getDropDate()->format('Y-m-d H:i') : null,
            'toolDocuments' => $this->getToolDocuments($document),
        ];
    }
414841
private function UDB3Media($document)
    {
        $media = [];

        if ($document) {
            $item = $document->getBody();
            // At the moment we do not include any media coming from UDB2.
            // If the mediaObject property contains data it's coming from UDB3.
            $item->mediaObject = isset($item->mediaObject) ? $item->mediaObject : [];
        }

        return $media;
    }
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;
    }
777055
public function getDocumentIdentifier($document)
    {
        return isset($this->documentIdentifiers[spl_object_hash($document)]) ?
            $this->documentIdentifiers[spl_object_hash($document)] : null;
    }
305280
public function getDocument($document, $rootNode)
	{
		$documentName = self::getName($document);
		$xpath = self::getXPath($document);

		if (!self::existsDocument($documentName))
		{
			throw new NotFoundException("Document " . $document . " doesn't exists in repository", 600);
		}

		$documentName = self::getFullFileName($documentName);
		
		if ($xpath == "")
		{
			$doc = XmlUtil::CreateXmlDocumentFromFile($documentName);
		}
		else
		{
			$doc = XmlUtil::CreateXmlDocumentFromStr("< $rootNode />", false);
			$source = XmlUtil::CreateXmlDocumentFromFile($documentName);
			
			$DocXpath = new DOMXPath($source);
			$nodes = $DocXpath->query($xpath);

			foreach ($nodes as $node)
			{
				$newNode = $doc->importNode($node);

				$doc->documentElement->appendChild($newNode);
			}

		}

		return $doc;
	}
1238661
public function getRawDocuments($returnType)
  {
    if ($returnType == DOC_TYPE_ARRAY) {
      $res = array();
      foreach ($this->_documents as $key => $value) {
        $res[$key] = CPS_Response::simpleXmlToArray($value);
      }
      return $res;
    } else if ($returnType == DOC_TYPE_STDCLASS) {
      $res = array();
      foreach ($this->_documents as $key => $value) {
        $res[$key] = CPS_Response::simpleXmlToStdClass($value);
      }
      return $res;
    }
    return $this->_documents;
  }
992203
public function normalize(MethodDoc $doc) : array
    {
        $docDescription = $docTags = $paramsSchema = $responseSchema = [];

        if (null !== $doc->getDescription()) {
            $docDescription['description'] = $doc->getDescription();
        }
        if (count($doc->getTagList())) {
            $docTags['tags'] = $doc->getTagList();
        }
        if (null !== $doc->getParamsDoc()) {
            $paramsSchema = [
                'params' => $this->typeDocNormalizer->normalize($doc->getParamsDoc())
            ];
        }
        // Create custom result schema only if provided
        if (null !== $doc->getResultDoc()) {
            $responseSchema['result'] = $this->typeDocNormalizer->normalize($doc->getResultDoc());
        }


        return [
            'identifier' => $doc->getIdentifier(),
            'name' =>$doc->getMethodName(),
        ]
            + $docDescription
            + $docTags
            + $paramsSchema
            + $responseSchema
            + $this->appendErrorsSchema($doc)
        ;
    }
1098548
public function getFieldValue($document, $field)
    {
        if (isset($this->reflFields[$field])) {
            return $this->reflFields[$field]->getValue($document);
        }
    }
497492
static BsonDocument getDocumentVersionDoc(final BsonDocument document) {
    if (document == null || !document.containsKey(DOCUMENT_VERSION_FIELD)) {
      return null;
    }
    return document.getDocument(DOCUMENT_VERSION_FIELD, null);
  }
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;
    }
967195
public function normalize(TypeDoc $docObject) : array
    {
        $docArray = [];

        $docArray = $this->appendIfNotNull($docArray, 'description', $docObject->getDescription());

        return $docArray
            + ['type' => $this->normalizeSchemaType($docObject)]
            + ['nullable' => $docObject->isNullable()]
            + ['required' => $docObject->isRequired()]
            + $this->appendMisc($docObject)
            + $this->appendDocEnum($docObject)
            + $this->appendMinMax($docObject)
            + $this->appendCollectionDoc($docObject)
        ;
    }
1177338
public function parseDocument(\DOMDocument $document)
    {
        foreach ($this->registry[DocumentExtension::class] as $extension) {
            $doc = $extension->parseDocument($this, $document);
            if ($doc) {
                return $doc;
            }
        }

        return null;
    }
855740
public function getDocumentNamespaces()
	{
		if ( ! $this->documentPrefixes )
		{
			if ( ! property_exists( $this, 'xbrlDocument' ) ) return null;
			$this->documentPrefixes = $this->xbrlDocument->getDocNamespaces( true );
		}

		return $this->documentPrefixes;
	}
127030
public function deleteDocument(Document $document)
    {
        $options = $document->getOptions(
            [
                'version',
                'version_type',
                'routing',
                'parent',
                'replication',
                'consistency',
                'refresh',
                'timeout',
            ]
        );

        return $this->deleteById($document->getId(), $options);
    }
655735
private function getTranslatableFields(Document $document, $prefix = '')
    {
        $result = [];
        foreach ($document->getFields() as $field) {
            if ($field instanceof Field) {
                if ($field->getType() == 'translatable') {
                    $result[] = $prefix.$field->getExposedName();
                }
            } elseif ($field instanceof EmbedOne) {
                $result = array_merge(
                    $result,
                    $this->getTranslatableFields(
                        $field->getDocument(),
                        $prefix.$field->getExposedName().'.'
                    )
                );
            } elseif ($field instanceof EmbedMany) {
                $result = array_merge(
                    $result,
                    $this->getTranslatableFields(
                        $field->getDocument(),
                        $prefix.$field->getExposedName().'.0.'
                    )
                );
            }
        }

        return $result;
    }
724188
protected function appendCollectionDoc(TypeDoc $docObject) : array
    {
        $docArray = [];
        if ($docObject instanceof CollectionDoc) {
            $siblingDocList = $this->getSiblingDocList($docObject);
            if (count($siblingDocList)) {
                $docArray['siblings'] = $siblingDocList;
            }
            if (true === $docObject->isAllowExtraSibling()) {
                $docArray['allowExtra'] = $docObject->isAllowExtraSibling();
            }
            if (true === $docObject->isAllowMissingSibling()) {
                $docArray['allowMissing'] = $docObject->isAllowMissingSibling();
            }
        }

        return $docArray;
    }