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

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

            if ($edgeCollectionsCount === 1) {
                $collection = $edgeCollections[0];
            }
        }

        if (is_array($document)) {
            $_edgeClass = $this->_edgeClass;
            $document = $_edgeClass::createFromArray($document);
        }
        if (null !== $label) {
            $document->set('$label', $label);
        }
        $document->setFrom($from);
        $document->setTo($to);
        $data                 = $document->getAll();
        $data[self::KEY_FROM] = $from;
        $data[self::KEY_TO]   = $to;

        $url = UrlHelper::buildUrl(Urls::URL_GRAPH, [$graph, Urls::URLPART_EDGE, $collection]);

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

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

        $document->setInternalId($edge[Edge::ENTRY_ID]);
        $document->setRevision($edge[Edge::ENTRY_REV]);

        $document->setIsNew(false);

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

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

            if ($edgeCollectionsCount === 1) {
                $collection = $edgeCollections[0];
            }
        }

        if (is_array($document)) {
            $_edgeClass = $this->_edgeClass;
            $document = $_edgeClass::createFromArray($document);
        }
        if (null !== $label) {
            $document->set('$label', $label);
        }
        $document->setFrom($from);
        $document->setTo($to);
        $data                 = $document->getAll();
        $data[self::KEY_FROM] = $from;
        $data[self::KEY_TO]   = $to;

        $url = UrlHelper::buildUrl(Urls::URL_GRAPH, [$graph, Urls::URLPART_EDGE, $collection]);

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

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

        $document->setInternalId($edge[Edge::ENTRY_ID]);
        $document->setRevision($edge[Edge::ENTRY_REV]);

        $document->setIsNew(false);

        return $document->getInternalId();
    }
public function saveEdge ( $ graph , $ from , $ to , $ label = null , $ document , $ collection = null ) { if ( $ graph instanceof Graph ) { $ graph = $ graph -> getKey ( ) ; } if ( $ collection === null ) { $ edgeCollections = $ this -> getEdgeCollections ( $ graph ) ; $ edgeCollectionsCount = count ( $ edgeCollections ) ; if ( $ edgeCollectionsCount !== 1 ) { throw new ClientException ( 'A collection must be provided.' ) ; } if ( $ edgeCollectionsCount === 1 ) { $ collection = $ edgeCollections [ 0 ] ; } } if ( is_array ( $ document ) ) { $ _edgeClass = $ this -> _edgeClass ; $ document = $ _edgeClass :: createFromArray ( $ document ) ; } if ( null !== $ label ) { $ document -> set ( '$label' , $ label ) ; } $ document -> setFrom ( $ from ) ; $ document -> setTo ( $ to ) ; $ data = $ document -> getAll ( ) ; $ data [ self :: KEY_FROM ] = $ from ; $ data [ self :: KEY_TO ] = $ to ; $ url = UrlHelper :: buildUrl ( Urls :: URL_GRAPH , [ $ graph , Urls :: URLPART_EDGE , $ collection ] ) ; $ response = $ this -> getConnection ( ) -> post ( $ url , $ this -> json_encode_wrapper ( $ data ) ) ; $ jsonArray = $ response -> getJson ( ) ; $ edge = $ jsonArray [ 'edge' ] ; $ document -> setInternalId ( $ edge [ Edge :: ENTRY_ID ] ) ; $ document -> setRevision ( $ edge [ Edge :: ENTRY_REV ] ) ; $ document -> setIsNew ( false ) ; return $ document -> getInternalId ( ) ; }
save an edge to a graph

This will save the edge to the graph and return the edges-document's id

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

@throws Exception

@param mixed  $graph      - graph name as a string or instance of Graph
@param mixed  $from       - the 'from' vertex
@param mixed  $to         - the 'to' vertex
@param mixed  $label      - (optional) a label for the edge
@param mixed  $document   - the edge-document to be added, can be passed as an edge object or an array
@param string $collection - if one uses a graph with more than one vertex collection one must provide the collection

@return mixed - id of edge created
@since 1.2
save an edge to a graph