public function saveVertex($graph, $document, $collection = null)
    {
        if ($graph instanceof Graph) {
            $graph = $graph->getKey();
        }

        if (is_array($document)) {
            $_documentClass = $this->_documentClass;

            $document = $_documentClass::createFromArray($document);
        }

        if ($collection === null) {
            $vertexCollections      = $this->getVertexCollections($graph);
            $vertexCollectionsCount = count($vertexCollections);
            if ($vertexCollectionsCount !== 1) {
                throw new ClientException('A collection must be provided.');
            }

            if ($vertexCollectionsCount === 1) {
                $collection = $vertexCollections[0];
            }
        }

        $data = $document->getAll();
        $url  = UrlHelper::buildUrl(Urls::URL_GRAPH, [$graph, Urls::URLPART_VERTEX, $collection]);

        $response = $this->getConnection()->post($url, $this->json_encode_wrapper($data));

        // This makes sure that if we're in batch mode, it will not go further and choke on the checks below.
        // Caution: Instead of a document ID, we are returning the batchpart object.
        // The Id of the BatchPart can be retrieved by calling getId() on it.
        // We're basically returning an object here, in order not to accidentally use the batch part id as the document id
        if ($batchPart = $response->getBatchPart()) {
            return $batchPart;
        }

        $jsonArray = $response->getJson();
        $vertex    = $jsonArray['vertex'];

        $document->setInternalId($vertex[Vertex::ENTRY_ID]);
        $document->setRevision($vertex[Vertex::ENTRY_REV]);

        $document->setIsNew(false);

        return $document->getInternalId();
    }
public function saveVertex($graph, $document, $collection = null)
    {
        if ($graph instanceof Graph) {
            $graph = $graph->getKey();
        }

        if (is_array($document)) {
            $_documentClass = $this->_documentClass;

            $document = $_documentClass::createFromArray($document);
        }

        if ($collection === null) {
            $vertexCollections      = $this->getVertexCollections($graph);
            $vertexCollectionsCount = count($vertexCollections);
            if ($vertexCollectionsCount !== 1) {
                throw new ClientException('A collection must be provided.');
            }

            if ($vertexCollectionsCount === 1) {
                $collection = $vertexCollections[0];
            }
        }

        $data = $document->getAll();
        $url  = UrlHelper::buildUrl(Urls::URL_GRAPH, [$graph, Urls::URLPART_VERTEX, $collection]);

        $response = $this->getConnection()->post($url, $this->json_encode_wrapper($data));

        // This makes sure that if we're in batch mode, it will not go further and choke on the checks below.
        // Caution: Instead of a document ID, we are returning the batchpart object.
        // The Id of the BatchPart can be retrieved by calling getId() on it.
        // We're basically returning an object here, in order not to accidentally use the batch part id as the document id
        if ($batchPart = $response->getBatchPart()) {
            return $batchPart;
        }

        $jsonArray = $response->getJson();
        $vertex    = $jsonArray['vertex'];

        $document->setInternalId($vertex[Vertex::ENTRY_ID]);
        $document->setRevision($vertex[Vertex::ENTRY_REV]);

        $document->setIsNew(false);

        return $document->getInternalId();
    }
public function saveVertex ( $ graph , $ document , $ collection = null ) { if ( $ graph instanceof Graph ) { $ graph = $ graph -> getKey ( ) ; } if ( is_array ( $ document ) ) { $ _documentClass = $ this -> _documentClass ; $ document = $ _documentClass :: createFromArray ( $ document ) ; } if ( $ collection === null ) { $ vertexCollections = $ this -> getVertexCollections ( $ graph ) ; $ vertexCollectionsCount = count ( $ vertexCollections ) ; if ( $ vertexCollectionsCount !== 1 ) { throw new ClientException ( 'A collection must be provided.' ) ; } if ( $ vertexCollectionsCount === 1 ) { $ collection = $ vertexCollections [ 0 ] ; } } $ data = $ document -> getAll ( ) ; $ url = UrlHelper :: buildUrl ( Urls :: URL_GRAPH , [ $ graph , Urls :: URLPART_VERTEX , $ collection ] ) ; $ response = $ this -> getConnection ( ) -> post ( $ url , $ this -> json_encode_wrapper ( $ data ) ) ; // This makes sure that if we're in batch mode, it will not go further and choke on the checks below. // Caution: Instead of a document ID, we are returning the batchpart object. // The Id of the BatchPart can be retrieved by calling getId() on it. // We're basically returning an object here, in order not to accidentally use the batch part id as the document id if ( $ batchPart = $ response -> getBatchPart ( ) ) { return $ batchPart ; } $ jsonArray = $ response -> getJson ( ) ; $ vertex = $ jsonArray [ 'vertex' ] ; $ document -> setInternalId ( $ vertex [ Vertex :: ENTRY_ID ] ) ; $ document -> setRevision ( $ vertex [ Vertex :: ENTRY_REV ] ) ; $ document -> setIsNew ( false ) ; return $ document -> getInternalId ( ) ; }
save a vertex to a graph

This will add the vertex-document to the graph and return the vertex id

This will throw if the vertex cannot be saved<br><br>

@throws Exception

@param mixed  $graph      - graph name as a string or instance of Graph
@param mixed  $document   - the vertex to be added, can be passed as a vertex object or an array
@param string $collection - if one uses a graph with more than one vertex collection one must provide
the collection to store the vertex.

@return string - id of vertex created
@since 1.2
save a vertex to a graph