/**
  * Create a graph
  *
  * This will create a graph using the given graph object and return an array of the created graph object's attributes.<br><br>
  *
  * @throws Exception
  * 
  * @param Graph $graph  - The graph object which holds the information of the graph to be created
  *
  * @return array
  * @since   1.2
  */
 public function createGraph(Graph $graph)
 {
     $edgeDefintions = array();
     foreach ($graph->getEdgeDefinitions() as $ed) {
         $edgeDefintions[] = $ed->transformToArray();
     }
     $params = array(self::OPTION_NAME => $graph->getKey(), self::OPTION_EDGE_DEFINITIONS => $edgeDefintions, self::OPTION_ORPHAN_COLLECTIONS => $graph->getOrphanCollections());
     $url = Urls::URL_GRAPH;
     $response = $this->getConnection()->post($url, $this->json_encode_wrapper($params));
     $json = $response->getJson();
     $graph->setInternalId($json['graph'][Graph::ENTRY_ID]);
     $graph->set(Graph::ENTRY_KEY, $json['graph'][self::OPTION_NAME]);
     $graph->setRevision($json['graph'][Graph::ENTRY_REV]);
     return $graph->getAll();
 }
<?php

namespace triagens\ArangoDb;

// get connection options from a helper file
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php';
try {
    // Setup connection, graph and graph handler
    $connection = new Connection($connectionOptions);
    $graphHandler = new GraphHandler($connection);
    $graph = new Graph();
    $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);