/** * Tests if the updateVertex method accepts an instance of Graph as first argument and extracts the graph name out of it. */ public function testUpdateVertexWithGraphInstance() { $this->createGraph(); $new = Vertex::createFromArray(array('_key' => 'vertex1', 'someKey' => 'foobar')); $this->assertTrue($this->graphHandler->updateVertex($this->graph, 'vertex1', $new)); }
/** * Get a single vertex from a graph * * This will throw if the vertex cannot be fetched from the server<br><br> * * @throws Exception * * @param mixed $graph - graph name as a string or instance of Graph * @param mixed $vertexId - the vertex identifier * @param array $options optional, an array of options: * <p> * <li><b>_includeInternals</b> - true to include the internal attributes. Defaults to false</li> * <li><b>includeInternals</b> - Deprecated, please use '_includeInternals'.</li> * <li><b>_ignoreHiddenAttributes</b> - true to show hidden attributes. Defaults to false</li> * <li><b>ignoreHiddenAttributes</b> - Deprecated, please use '_ignoreHiddenAttributes'.</li> * </p> * @param string $collection - if one uses a graph with more than one vertex collection one must provide the collection * to load the vertex. * * @return Document * @since 1.2 */ public function getVertex($graph, $vertexId, array $options = array(), $collection = null) { if ($graph instanceof Graph) { $graph = $graph->getKey(); } $parts = explode("/", $vertexId); if (count($parts) === 2) { $vertexId = $parts[1]; $collection = $parts[0]; } if (count($this->getVertexCollections($graph)) !== 1 && $collection === null) { throw new ClientException('A collection must be provided.'); } else { if (count($this->getVertexCollections($graph)) === 1 && $collection === null) { $collection = $this->getVertexCollections($graph); $collection = $collection[0]; } } $url = UrlHelper::buildUrl(Urls::URL_GRAPH, array($graph, Urls::URLPART_VERTEX, $collection, $vertexId)); $response = $this->getConnection()->get($url); $jsonArray = $response->getJson(); $vertex = $jsonArray['vertex']; $options['_isNew'] = false; return Vertex::createFromArray($vertex, $options); }
/** * Create an array of Vertex from the input array * * @param array $data - array of incoming "vertex" arrays * * @return void */ private function addVerticesFromArray(array $data) { $this->_result[] = Vertex::createFromArray($data, $this->_options); }
/** * Intermediate function to call the createFromArray function from the right context * * @param $data * @param $options * * @return Document */ public function createFromArrayWithContext($data, $options) { return Vertex::createFromArray($data, $options); }
$graph->set('_key', 'Graph'); $graph->setVerticesCollection('VertexCollection'); $graph->setEdgesCollection('EdgeCollection'); try { $graphHandler->dropGraph($graph); } catch (\Exception $e) { // graph may not yet exist. ignore this error for now } $graphHandler->createGraph($graph); // Define some arrays to build the content of the vertices and edges $vertex1Array = array('_key' => 'vertex1', 'someKey1' => 'someValue1'); $vertex2Array = array('_key' => 'vertex2', 'someKey2' => 'someValue2'); $edge1Array = array('_key' => 'edge1', 'someEdgeKey1' => 'someEdgeValue1'); // Create documents for 2 vertices and a connecting edge $vertex1 = Vertex::createFromArray($vertex1Array); $vertex2 = Vertex::createFromArray($vertex2Array); $edge1 = Edge::createFromArray($edge1Array); // Save the vertices $saveResult1 = $graphHandler->saveVertex('Graph', $vertex1); $saveResult2 = $graphHandler->saveVertex('Graph', $vertex2); // Get the vertices $getResult1 = $graphHandler->getVertex('Graph', 'vertex1'); $getResult2 = $graphHandler->getVertex('Graph', 'vertex2'); // check if vertex exists var_dump($graphHandler->hasVertex('Graph', 'vertex1')); // Save the connecting edge $saveEdgeResult1 = $graphHandler->saveEdge('Graph', $vertex1->getHandle(), $vertex2->getHandle(), 'somelabelValue', $edge1); // check if edge exists var_dump($graphHandler->hasEdge('Graph', 'edge1')); // Get the connecting edge $getEdgeResult1 = $graphHandler->getEdge('Graph', 'edge1');
/** */ public function testsaveGetUpdateReplaceRemoveVertex() { $vertex1 = Vertex::createFromArray($this->vertex1Array); $ex = null; try { $this->graphHandler->saveVertex($this->graphName, $vertex1); } catch (Exception $e) { $ex = $e->getMessage(); } $this->assertTrue($ex == 'A collection must be provided.'); $this->createGraph(); $ex = null; try { $this->graphHandler->getVertex($this->graphName, $this->vertex1Array["_key"]); } catch (Exception $e) { $ex = $e->getMessage(); } $this->assertTrue($ex == 'A collection must be provided.'); $v1 = $this->graphHandler->getVertex($this->graphName, $this->vertex1Array["_key"], array(), $this->v1); $v2 = $this->graphHandler->getVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], array()); $this->assertTrue($v1->getInternalKey() == $v2->getInternalKey()); $v1 = $this->graphHandler->getVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], array()); $v = Vertex::createFromArray($this->vertex7Array); $v->setRevision($v1->getRevision()); $ex = null; try { $this->graphHandler->replaceVertex($this->graphName, $this->vertex1Array["_key"], $v, array()); } catch (Exception $e) { $ex = $e->getMessage(); } $this->assertTrue($ex == 'A collection must be provided.'); $v1 = $this->graphHandler->getVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], array()); $v = Vertex::createFromArray($this->vertex7Array); $v->setRevision($v1->getRevision()); $this->assertTrue($this->graphHandler->replaceVertex($this->graphName, $this->vertex1Array["_key"], $v, array('revision' => $v1->getRevision()), $this->v1)); $v1 = $this->graphHandler->getVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], array()); $v = Vertex::createFromArray($this->vertex7Array); $v->setRevision($v1->getRevision()); $this->assertTrue($this->graphHandler->replaceVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], $v, array('revision' => true))); $ex = null; try { $this->graphHandler->updateVertex($this->graphName, $this->vertex1Array["_key"], $v, array()); } catch (Exception $e) { $ex = $e->getMessage(); } $this->assertTrue($ex == 'A collection must be provided.'); $v1 = $this->graphHandler->getVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], array()); $v = Vertex::createFromArray($this->vertex7Array); $v->setRevision($v1->getRevision()); $this->assertTrue($this->graphHandler->updateVertex($this->graphName, $this->vertex1Array["_key"], $v, array('revision' => true), $this->v1)); $v1 = $this->graphHandler->getVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], array()); $v = Vertex::createFromArray($this->vertex7Array); $v->setRevision($v1->getRevision()); $this->assertTrue($this->graphHandler->updateVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], $v, array('revision' => $v1->getRevision()))); //removeVertex($graph, $vertexId, $revision = null, $options = array(), $collection = null) $ex = null; try { $this->graphHandler->removeVertex($this->graphName, $this->vertex1Array["_key"], null, array()); } catch (Exception $e) { $ex = $e->getMessage(); } $this->assertTrue($ex == 'A collection must be provided.'); $v1 = $this->graphHandler->getVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], array()); $this->assertTrue($this->graphHandler->removeVertex($this->graphName, $this->v1 . "/" . $this->vertex1Array["_key"], $v1->getRevision(), array())); }
public function createGraph() { $vertex1 = Vertex::createFromArray($this->vertex1Array); $vertex2 = Vertex::createFromArray($this->vertex2Array); $vertex3 = Vertex::createFromArray($this->vertex3Array); $vertex4 = Vertex::createFromArray($this->vertex4Array); $vertex5 = Vertex::createFromArray($this->vertex5Array); $edge1 = Edge::createFromArray($this->edge1Array); $edge2 = Edge::createFromArray($this->edge2Array); $edge3 = Edge::createFromArray($this->edge3Array); $edge4 = Edge::createFromArray($this->edge4Array); $edge5 = Edge::createFromArray($this->edge5Array); $this->graphHandler->saveVertex($this->graphName, $vertex1); $this->graphHandler->saveVertex($this->graphName, $vertex2); $this->graphHandler->saveVertex($this->graphName, $vertex3); $this->graphHandler->saveVertex($this->graphName, $vertex4); $this->graphHandler->saveVertex($this->graphName, $vertex5); $this->graphHandler->getVertex($this->graphName, $this->vertex1Name); $this->graphHandler->getVertex($this->graphName, $this->vertex2Name); $this->graphHandler->getVertex($this->graphName, $this->vertex3Name); $this->graphHandler->getVertex($this->graphName, $this->vertex4Name); $this->graphHandler->getVertex($this->graphName, $this->vertex5Name); $this->graphHandler->saveEdge($this->graphName, $this->vertexCollectionName . "/" . $this->vertex1Name, $this->vertexCollectionName . "/" . $this->vertex2Name, $this->edgeLabel1, $edge1); $this->graphHandler->saveEdge($this->graphName, $this->vertexCollectionName . "/" . $this->vertex2Name, $this->vertexCollectionName . "/" . $this->vertex3Name, $this->edgeLabel2, $edge2); $this->graphHandler->saveEdge($this->graphName, $this->vertexCollectionName . "/" . $this->vertex2Name, $this->vertexCollectionName . "/" . $this->vertex4Name, $this->edgeLabel3, $edge3); $this->graphHandler->saveEdge($this->graphName, $this->vertexCollectionName . "/" . $this->vertex5Name, $this->vertexCollectionName . "/" . $this->vertex1Name, $this->edgeLabel4, $edge4); $this->graphHandler->saveEdge($this->graphName, $this->vertexCollectionName . "/" . $this->vertex5Name, $this->vertexCollectionName . "/" . $this->vertex2Name, $this->edgeLabel5, $edge5); }