public function saveEdge($collection, $from, $to, $document, array $options = [])
    {
        $collection = $this->makeCollection($collection);

        if (is_array($document)) {
            $_edgeClass = $this->_edgeClass;
            $document = $_edgeClass::createFromArray($document);
        }
        $document->setFrom($from);
        $document->setTo($to);

        $params = $this->includeOptionsInParams(
            $options, [
                'waitForSync'      => $this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC),
                'createCollection' => $this->getConnectionOption(ConnectionOptions::OPTION_CREATE)
            ]
        );

        $this->createCollectionIfOptions($collection, $params);

        $data = $document->getAllForInsertUpdate();

        $url      = UrlHelper::appendParamsUrl(Urls::URL_EDGE . '/' . $collection, $params);
        $response = $this->getConnection()->post($url, $this->json_encode_wrapper($data));

        $location = $response->getLocationHeader();
        if (!$location) {
            throw new ClientException('Did not find location header in server response');
        }

        $json = $response->getJson();
        $id   = UrlHelper::getDocumentIdFromLocation($location);

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

        if ($id !== $document->getId()) {
            throw new ClientException('Got an invalid response from the server');
        }

        $document->setIsNew(false);

        return $document->getId();
    }
public function saveEdge($collection, $from, $to, $document, array $options = [])
    {
        $collection = $this->makeCollection($collection);

        if (is_array($document)) {
            $_edgeClass = $this->_edgeClass;
            $document = $_edgeClass::createFromArray($document);
        }
        $document->setFrom($from);
        $document->setTo($to);

        $params = $this->includeOptionsInParams(
            $options, [
                'waitForSync'      => $this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC),
                'createCollection' => $this->getConnectionOption(ConnectionOptions::OPTION_CREATE)
            ]
        );

        $this->createCollectionIfOptions($collection, $params);

        $data = $document->getAllForInsertUpdate();

        $url      = UrlHelper::appendParamsUrl(Urls::URL_EDGE . '/' . $collection, $params);
        $response = $this->getConnection()->post($url, $this->json_encode_wrapper($data));

        $location = $response->getLocationHeader();
        if (!$location) {
            throw new ClientException('Did not find location header in server response');
        }

        $json = $response->getJson();
        $id   = UrlHelper::getDocumentIdFromLocation($location);

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

        if ($id !== $document->getId()) {
            throw new ClientException('Got an invalid response from the server');
        }

        $document->setIsNew(false);

        return $document->getId();
    }
public function saveEdge ( $ collection , $ from , $ to , $ document , array $ options = [ ] ) { $ collection = $ this -> makeCollection ( $ collection ) ; if ( is_array ( $ document ) ) { $ _edgeClass = $ this -> _edgeClass ; $ document = $ _edgeClass :: createFromArray ( $ document ) ; } $ document -> setFrom ( $ from ) ; $ document -> setTo ( $ to ) ; $ params = $ this -> includeOptionsInParams ( $ options , [ 'waitForSync' => $ this -> getConnectionOption ( ConnectionOptions :: OPTION_WAIT_SYNC ) , 'createCollection' => $ this -> getConnectionOption ( ConnectionOptions :: OPTION_CREATE ) ] ) ; $ this -> createCollectionIfOptions ( $ collection , $ params ) ; $ data = $ document -> getAllForInsertUpdate ( ) ; $ url = UrlHelper :: appendParamsUrl ( Urls :: URL_EDGE . '/' . $ collection , $ params ) ; $ response = $ this -> getConnection ( ) -> post ( $ url , $ this -> json_encode_wrapper ( $ data ) ) ; $ location = $ response -> getLocationHeader ( ) ; if ( ! $ location ) { throw new ClientException ( 'Did not find location header in server response' ) ; } $ json = $ response -> getJson ( ) ; $ id = UrlHelper :: getDocumentIdFromLocation ( $ location ) ; $ document -> setInternalId ( $ json [ Edge :: ENTRY_ID ] ) ; $ document -> setRevision ( $ json [ Edge :: ENTRY_REV ] ) ; if ( $ id !== $ document -> getId ( ) ) { throw new ClientException ( 'Got an invalid response from the server' ) ; } $ document -> setIsNew ( false ) ; return $ document -> getId ( ) ; }
save an edge to an edge-collection

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

This will throw if the document cannot be saved

@throws Exception

@param mixed $collection        - collection id as string or number
@param mixed $from              - from vertex
@param mixed $to                - to vertex
@param mixed $document          - the edge-document to be added, can be passed as an object or an array
@param array $options           - optional, array of options.
<p>Options are :<br>
<li>'createCollection' - create the collection if it does not yet exist.</li>
<li>'waitForSync' -  if set to true, then all removal operations will instantly be synchronised to disk.<br>
If this is not specified, then the collection's default sync behavior will be applied.</li>
</p>

@return mixed - id of document created
@since 1.0
save an edge to an edge - collection