src/Persister/DocumentPersister.php
public function insert($document): ?PostInsertId
    {
        /** @var DocumentMetadata $class */
        $class = $this->dm->getClassMetadata(get_class($document));
        $idGenerator = $this->dm->getUnitOfWork()->getIdGenerator($class->idGeneratorType);
        $postIdGenerator = $idGenerator->isPostInsertGenerator();

        $id = $postIdGenerator ? null : $class->getSingleIdentifier($document);
        $body = $this->prepareUpdateData($document)['body'];

        $response = $this->collection->create($id, $body);
        $data = $response->getData();

        foreach ($class->attributesMetadata as $field) {
            if (! $field instanceof FieldMetadata) {
                continue;
            }

            if ($field->indexName) {
                $field->setValue($document, $data['_index'] ?? null);
            }

            if ($field->typeName) {
                $field->setValue($document, $data['_type'] ?? null);
            }
        }

        $postInsertId = null;
        if ($postIdGenerator) {
            $postInsertId = new PostInsertId($document, $this->collection->getLastInsertedId());
        }

        return $postInsertId;
    }
public function insert($document): ?PostInsertId
    {
        /** @var DocumentMetadata $class */
        $class = $this->dm->getClassMetadata(get_class($document));
        $idGenerator = $this->dm->getUnitOfWork()->getIdGenerator($class->idGeneratorType);
        $postIdGenerator = $idGenerator->isPostInsertGenerator();

        $id = $postIdGenerator ? null : $class->getSingleIdentifier($document);
        $body = $this->prepareUpdateData($document)['body'];

        $response = $this->collection->create($id, $body);
        $data = $response->getData();

        foreach ($class->attributesMetadata as $field) {
            if (! $field instanceof FieldMetadata) {
                continue;
            }

            if ($field->indexName) {
                $field->setValue($document, $data['_index'] ?? null);
            }

            if ($field->typeName) {
                $field->setValue($document, $data['_type'] ?? null);
            }
        }

        $postInsertId = null;
        if ($postIdGenerator) {
            $postInsertId = new PostInsertId($document, $this->collection->getLastInsertedId());
        }

        return $postInsertId;
    }
public function insert ( $ document ) : ? PostInsertId { /** @var DocumentMetadata $class */ $ class = $ this -> dm -> getClassMetadata ( get_class ( $ document ) ) ; $ idGenerator = $ this -> dm -> getUnitOfWork ( ) -> getIdGenerator ( $ class -> idGeneratorType ) ; $ postIdGenerator = $ idGenerator -> isPostInsertGenerator ( ) ; $ id = $ postIdGenerator ? null : $ class -> getSingleIdentifier ( $ document ) ; $ body = $ this -> prepareUpdateData ( $ document ) [ 'body' ] ; $ response = $ this -> collection -> create ( $ id , $ body ) ; $ data = $ response -> getData ( ) ; foreach ( $ class -> attributesMetadata as $ field ) { if ( ! $ field instanceof FieldMetadata ) { continue ; } if ( $ field -> indexName ) { $ field -> setValue ( $ document , $ data [ '_index' ] ?? null ) ; } if ( $ field -> typeName ) { $ field -> setValue ( $ document , $ data [ '_type' ] ?? null ) ; } } $ postInsertId = null ; if ( $ postIdGenerator ) { $ postInsertId = new PostInsertId ( $ document , $ this -> collection -> getLastInsertedId ( ) ) ; } return $ postInsertId ; }
Insert a document in the collection.

@param object $document

@return PostInsertId|null
Insert a document in the collection .