A handler that manages graphs.

package ArangoDBClient
since 1.2
inherited_from \ArangoDBClient\Handler

 Methods

Construct a new handler

__construct(\ArangoDBClient\Connection $connection) 
Inherited

Parameters

$connection

\ArangoDBClient\Connection
  • connection to be used

adds an edge definition to the graph.

addEdgeDefinition(mixed $graph, \ArangoDBClient\EdgeDefinition $edgeDefinition) : \ArangoDBClient\Graph

This will add a further edge definition to the graph.

since 2.2

Parameters

$graph

mixed
  • graph name as a string or instance of Graph

$edgeDefinition

\ArangoDBClient\EdgeDefinition
  • the new edge definition.

Exceptions

\ArangoDBClient\Exception

Returns

\ArangoDBClient\Graph

add an orphan collection to the graph.

addOrphanCollection(mixed $graph, string $orphanCollection) : \ArangoDBClient\Graph

This will add a further orphan collection to the graph.

since 2.2

Parameters

$graph

mixed
  • graph name as a string or instance of Graph

$orphanCollection

string
  • the orphan collection to be added as string.

Exceptions

\ArangoDBClient\Exception

Returns

\ArangoDBClient\Graph

Clears the GraphHandler's cache

clearCache() : \ArangoDBClient\GraphHandler
fluent This method is part of a fluent interface and will return the same instance

Returns

\ArangoDBClient\GraphHandler

Create a graph

createGraph(\ArangoDBClient\Graph $graph) : array

This will create a graph using the given graph object and return an array of the created graph object's attributes.

since 1.2

Parameters

$graph

\ArangoDBClient\Graph
  • The graph object which holds the information of the graph to be created

Exceptions

\ArangoDBClient\Exception

Returns

array

deletes an edge definition from the graph.

deleteEdgeDefinition(mixed $graph, string $edgeDefinition, boolean $dropCollection = false) : \ArangoDBClient\Graph

This will delete an edge definition from the graph.

since 2.2

Parameters

$graph

mixed
  • graph name as a string or instance of Graph

$edgeDefinition

string
  • the name of the edge definitions relation.

$dropCollection

boolean
  • if set to true the edge definitions collections are deleted.

Exceptions

\ArangoDBClient\Exception

Returns

\ArangoDBClient\Graph

deletes an orphan collection from the graph.

deleteOrphanCollection(mixed $graph, string $orphanCollection, boolean $dropCollection = false) : \ArangoDBClient\Graph

This will delete an orphan collection from the graph.

since 2.2

Parameters

$graph

mixed
  • graph name as a string or instance of Graph

$orphanCollection

string
  • the orphan collection to be removed as string.

$dropCollection

boolean
  • if set to true the collection is deleted, not just removed from the graph.

Exceptions

\ArangoDBClient\Exception

Returns

\ArangoDBClient\Graph

Drop a graph and remove all its vertices and edges, also drops vertex and edge collections<br><br>

dropGraph(mixed $graph, boolean $dropCollections = true) : boolean
since 1.2

Parameters

$graph

mixed
  • graph name as a string or instance of Graph

$dropCollections

boolean
  • if set to false the graphs collections will not be dropped.

Exceptions

\ArangoDBClient\Exception

Returns

boolean- always true, will throw if there is an error

Checks if caching in enabled

getCacheEnabled() : boolean

Returns

boolean

Get a single edge from a graph

getEdge(mixed $graph, mixed $edgeId, array $options = array(), string $collection = null) : \ArangoDBClient\Document

This will throw if the edge cannot be fetched from the server

since 1.2

Parameters

$graph

mixed
  • graph name as a string or instance of Graph

$edgeId

mixed
  • edge identifier

$options

array

optional, array of options

  • _includeInternals - true to include the internal attributes. Defaults to false
  • _ignoreHiddenAttributes - true to show hidden attributes. Defaults to false
  • $collection

    string
    • if one uses a graph with more than one vertex collection one must provide the collection

    Exceptions

    \ArangoDBClient\Exception

    Returns

    \ArangoDBClient\Document- the edge document fetched from the server

    gets all edge collections from the graph.

    getEdgeCollections(mixed $graph) : array

    This will get all edge collections from the graph.

    If this method or any method that calls this method is used in batch mode and caching is off,
    then for each call, this method will make an out of batch API call to the db in order to get the appropriate collections.

    If caching is on, then the GraphHandler will only call the DB API once for the chosen graph, and return data from cache for the following calls.

    since 2.2

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    Exceptions

    \ArangoDBClient\Exception

    Returns

    array

    Get a graph

    getGraph(String $graph, array $options = array()) : \ArangoDBClient\Graph | false

    This will get a graph.

    since 1.2

    Parameters

    $graph

    String
    • The name of the graph

    $options

    array
    • Options to pass to the method

    Exceptions

    \ArangoDBClient\ClientException

    Returns

    \ArangoDBClient\Graphfalse

    Get a single vertex from a graph

    getVertex(mixed $graph, mixed $vertexId, array $options = array(), string $collection = null) : \ArangoDBClient\Document

    This will throw if the vertex cannot be fetched from the server

    since 1.2

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    $vertexId

    mixed
    • the vertex identifier

    $options

    array

    optional, an array of options:

  • _includeInternals - true to include the internal attributes. Defaults to false
  • _ignoreHiddenAttributes - true to show hidden attributes. Defaults to false
  • $collection

    string
    • if one uses a graph with more than one vertex collection one must provide the collection to load the vertex.

    Exceptions

    \ArangoDBClient\Exception

    Returns

    \ArangoDBClient\Document

    gets all vertex collection from the graph.

    getVertexCollections(mixed $graph, array $options = array()) : array

    This will get all vertex collection (orphans and used in edge definitions) from the graph.

    If this method or any method that calls this method is used in batch mode and caching is off,
    then for each call, this method will make an out of batch API call to the db in order to get the appropriate collections.

    If caching is on, then the GraphHandler will only call the DB API once for the chosen graph, and return data from cache for the following calls.

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    $options

    array
    • optional, an array of options

      Options are :

    • 'excludeOrphans' - boolean value: true to exclude the orphans or false to include orphans in the result.
      Defaults to false

    Exceptions

    \ArangoDBClient\ClientException@since 2.2

    Returns

    array

    Check if an edge exists

    hasEdge(mixed $graph, mixed $edgeId) : boolean

    This will call self::getEdge() internally and checks if there was an exception thrown which represents an 404 request.

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    $edgeId

    mixed
    • the vertex identifier

    Exceptions

    \ArangoDBClient\Exception When any other error than a 404 occurs

    Returns

    boolean

    Check if a vertex exists

    hasVertex(mixed $graph, mixed $vertexId) : boolean

    This will call self::getVertex() internally and checks if there was an exception thrown which represents an 404 request.

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    $vertexId

    mixed
    • the vertex identifier

    Exceptions

    \ArangoDBClient\Exception When any other error than a 404 occurs

    Returns

    boolean

    Get a graph's properties<br><br>

    properties(mixed $graph) : boolean
    since 1.2

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    Exceptions

    \ArangoDBClient\Exception

    Returns

    boolean- Returns an array of attributes. Will throw if there is an error

    Remove a edge from a graph, identified by the graph name and edge id<br><br>

    removeEdge(mixed $graph, mixed $edgeId, mixed $revision = null, mixed $options = array(), string $collection = null) : boolean
    since 1.2

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    $edgeId

    mixed
    • edge id as string or number

    $revision

    mixed
    • optional revision of the edge to be deleted

    $options

    mixed

    optional, array of options (see below) or the boolean value for $policy (for compatibility prior to version 1.1 of this method)

  • policy - update policy to be used in case of conflict ('error', 'last' or NULL [use default])
  • waitForSync - can be used to force synchronisation of the document removal operation to disk even in case that the waitForSync flag had been disabled for the entire collection
  • $collection

    string
    • if one uses a graph with more than one vertex collection one must provide the collection

    Exceptions

    \ArangoDBClient\Exception

    Returns

    boolean- always true, will throw if there is an error

    Remove a vertex from a graph, identified by the graph name and vertex id<br><br>

    removeVertex(mixed $graph, mixed $vertexId, mixed $revision = null, mixed $options = array(), string $collection = null) : boolean
    since 1.2

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    $vertexId

    mixed
    • the vertex id as string or number

    $revision

    mixed
    • optional, the revision of the vertex to be deleted

    $options

    mixed

    optional, an array of options (see below) or the boolean value for $policy (for compatibility prior to version 1.1 of this method)

  • policy - update policy to be used in case of conflict ('error', 'last' or NULL [use default])
  • waitForSync - can be used to force synchronisation of the document removal operation to disk even in case that the waitForSync flag had been disabled for the entire collection
  • $collection

    string
    • if one uses a graph with more than one vertex collection one must provide the collection

    Exceptions

    \ArangoDBClient\Exception

    Returns

    boolean- always true, will throw if there is an error

    Replace an existing edge in a graph, identified graph name and edge id

    replaceEdge(mixed $graph, mixed $edgeId, mixed $label, \ArangoDBClient\Edge $document, mixed $options = array(), string $collection = null) : boolean

    This will replace the edge on the server

    This will throw if the edge cannot be Replaced

    If policy is set to error (locally or globally through the ConnectionOptions) and the passed document has a _rev value set, the database will check that the revision of the to-be-replaced edge is the same as the one given.

    since 1.2

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    $edgeId

    mixed
    • edge id as string or number

    $label

    mixed
    • label for the edge or ''

    $document

    \ArangoDBClient\Edge
    • edge document to be updated

    $options

    mixed

    optional, array of options (see below) or the boolean value for $policy (for compatibility prior to version 1.1 of this method)

  • policy - update policy to be used in case of conflict ('error', 'last' or NULL [use default])
  • waitForSync - can be used to force synchronisation of the document replacement operation to disk even in case that the waitForSync flag had been disabled for the entire collection
  • $collection

    string
    • if one uses a graph with more than one vertex collection one must provide the collection

    Exceptions

    \ArangoDBClient\Exception

    Returns

    boolean- always true, will throw if there is an error

    replaces an edge definition of the graph.

    replaceEdgeDefinition(mixed $graph, \ArangoDBClient\EdgeDefinition $edgeDefinition) : \ArangoDBClient\Graph

    This will replace an edge definition in the graph.

    since 2.2

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    $edgeDefinition

    \ArangoDBClient\EdgeDefinition
    • the edge definition.

    Exceptions

    \ArangoDBClient\Exception

    Returns

    \ArangoDBClient\Graph

    Replace an existing vertex in a graph, identified graph name and vertex id

    replaceVertex(mixed $graph, mixed $vertexId, \ArangoDBClient\Document $document, mixed $options = array(), string $collection = null) : boolean

    This will update the vertex on the server

    If policy is set to error (locally or globally through the ConnectionOptions) and the passed document has a _rev value set, the database will check that the revision of the to-be-replaced vertex is the same as the one given.

    since 1.2

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    $vertexId

    mixed
    • the vertex id as string or number

    $document

    \ArangoDBClient\Document
    • the vertex-document to be updated

    $options

    mixed

    optional, an array of options (see below) or the boolean value for $policy (for compatibility prior to version 1.1 of this method):

  • revision - revision for conditional updates ('some-revision-id' [use the passed in revision id], false or true [use document's revision])
  • policy - update policy to be used in case of conflict ('error', 'last' or NULL [use default])
  • waitForSync - can be used to force synchronisation of the document replacement operation to disk even in case that the waitForSync flag had been disabled for the entire collection
  • $collection

    string
    • if one uses a graph with more than one vertex collection one must provide the collection

    Exceptions

    \ArangoDBClient\Exception

    Returns

    boolean- always true, will throw if there is an error

    save an edge to a graph

    saveEdge(mixed $graph, mixed $from, mixed $to, mixed $label = null, mixed $document, string $collection = null) : mixed

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

    This will throw if the edge cannot be saved

    since 1.2

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    $from

    mixed
    • the 'from' vertex

    $to

    mixed
    • the 'to' vertex

    $label

    mixed
    • (optional) a label for the edge

    $document

    mixed
    • the edge-document to be added, can be passed as an edge object or an array

    $collection

    string
    • if one uses a graph with more than one vertex collection one must provide the collection

    Exceptions

    \ArangoDBClient\Exception

    Returns

    mixed- id of edge created

    save a vertex to a graph

    saveVertex(mixed $graph, mixed $document, string $collection = null) : string

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

    This will throw if the vertex cannot be saved

    since 1.2

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    $document

    mixed
    • the vertex to be added, can be passed as a vertex object or an array

    $collection

    string
    • if one uses a graph with more than one vertex collection one must provide the collection to store the vertex.

    Exceptions

    \ArangoDBClient\Exception

    Returns

    string- id of vertex created

    Sets the batchsize for any method creating a cursor.

    setBatchsize(integer $batchsize) 

    Will be reset after the cursor has been created.

    Parameters

    $batchsize

    integer

    setCacheEnabled()

    setCacheEnabled(boolean $useCache) : \ArangoDBClient\GraphHandler
    fluent This method is part of a fluent interface and will return the same instance

    Parameters

    $useCache

    boolean

    Returns

    \ArangoDBClient\GraphHandler

    Sets the count for any method creating a cursor.

    setCount(integer $count) 

    Will be reset after the cursor has been created.

    Parameters

    $count

    integer

    Sets the document class to use

    setDocumentClass(string $class) : \ArangoDBClient\DocumentClassable
    Inherited

    Parameters

    $class

    string

    Document class to use

    Returns

    \ArangoDBClient\DocumentClassable

    Sets the edge class to use

    setEdgeClass(string $class) : \ArangoDBClient\DocumentClassable
    Inherited

    Parameters

    $class

    string

    Edge class to use

    Returns

    \ArangoDBClient\DocumentClassable

    Sets the limit for any method creating a cursor.

    setLimit(integer $limit) 

    Will be reset after the cursor has been created.

    Parameters

    $limit

    integer

    Update an existing edge in a graph, identified by graph name and edge id

    updateEdge(mixed $graph, mixed $edgeId, mixed $label, \ArangoDBClient\Edge $document, mixed $options = array(), string $collection = null) : boolean

    This will update the edge on the server

    This will throw if the edge cannot be updated

    If policy is set to error (locally or globally through the ConnectionOptions) and the passed edge-document has a _rev value set, the database will check that the revision of the to-be-replaced document is the same as the one given.

    since 1.2

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    $edgeId

    mixed
    • edge id as string or number

    $label

    mixed
    • label for the edge or ''

    $document

    \ArangoDBClient\Edge
    • patch edge-document which contains the attributes and values to be updated

    $options

    mixed

    optional, array of options (see below)

  • policy - update policy to be used in case of conflict ('error', 'last' or NULL [use default])
  • keepNull - can be used to instruct ArangoDB to delete existing attributes instead setting their values to null. Defaults to true (keep attributes when set to null)
  • waitForSync - can be used to force synchronisation of the document update operation to disk even in case that the waitForSync flag had been disabled for the entire collection
  • $collection

    string
    • if one uses a graph with more than one vertex collection one must provide the collection

    Exceptions

    \ArangoDBClient\Exception

    Returns

    boolean- always true, will throw if there is an error

    Update an existing vertex in a graph, identified by graph name and vertex id

    updateVertex(mixed $graph, mixed $vertexId, \ArangoDBClient\Document $document, mixed $options = array(), string $collection = null) : boolean

    This will update the vertex on the server

    This will throw if the vertex cannot be updated

    If policy is set to error (locally or globally through the ConnectionOptions) and the passed vertex-document has a _rev value set, the database will check that the revision of the to-be-replaced document is the same as the one given.

    since 1.2

    Parameters

    $graph

    mixed
    • graph name as a string or instance of Graph

    $vertexId

    mixed
    • the vertex id as string or number

    $document

    \ArangoDBClient\Document
    • the patch vertex-document which contains the attributes and values to be updated

    $options

    mixed

    optional, an array of options (see below)

  • policy - update policy to be used in case of conflict ('error', 'last' or NULL [use default])
  • keepNull - can be used to instruct ArangoDB to delete existing attributes instead setting their values to null. Defaults to true (keep attributes when set to null)
  • waitForSync - can be used to force synchronisation of the document update operation to disk even in case that the waitForSync flag had been disabled for the entire collection
  • $collection

    string
    • if one uses a graph with more than one vertex collection one must provide the collection

    Exceptions

    \ArangoDBClient\Exception

    Returns

    boolean- always true, will throw if there is an error

    Add a transaction header to the array of headers in case this is a transactional operation

    addTransactionHeader(array $headers, mixed $collection) 
    Inherited

    Parameters

    $headers

    array
    • already existing headers

    $collection

    mixed
    • any type of collection (can be StreamingTransactionCollection or other)

    Return the connection object

    getConnection() : \ArangoDBClient\Connection
    Inherited

    Returns

    \ArangoDBClient\Connection- the connection object

    Return a connection option This is a convenience function that calls json_encode_wrapper on the connection

    getConnectionOption($optionName) : mixed
    Inherited

    Parameters

    $optionName

    • The option to return a value for

    Exceptions

    \ArangoDBClient\ClientException

    Returns

    mixed- the option's value

    Helper function that runs through the options given and includes them into the parameters array given.

    includeOptionsInBody(array $options, array $body, array $includeArray = array()) : array
    Inherited

    Only options that are set in $includeArray will be included. This is only for options that are to be sent to the ArangoDB server in a json body(like 'limit', 'skip', etc...) .

    Parameters

    $options

    array
    • The options array that holds the options to include in the parameters

    $body

    array
    • The array into which the options will be included.

    $includeArray

    array
    • The array that defines which options are allowed to be included, and what their default value is. for example: 'waitForSync'=>true

    Returns

    array$params - array of parameters for use in a url

    Return a json encoded string for the array passed.

    json_encode_wrapper(array $body) : string
    Inherited

    This is a convenience function that calls json_encode_wrapper on the connection

    Parameters

    $body

    array
    • The body to encode into json

    Exceptions

    \ArangoDBClient\ClientException

    Returns

    string- json string of the body that was passed

    Turn a value into a collection name

    makeCollection(mixed $value) : string
    Inherited

    Parameters

    $value

    mixed
    • document, collection or string

    Exceptions

    \ArangoDBClient\ClientException

    Returns

    string- collection name

     Properties

     

    Document class to use

    $_documentClass : string

    Default

    '\ArangoDBClient\Document'
     

    Edge class to use

    $_edgeClass : string

    Default

    '\ArangoDBClient\Edge'
     

    GraphHandler cache store

    $cache 

    Default

     

    boolean GraphHandler use cache store

    $cacheEnabled : 

    Default

    false
     

    Connection object

    $_connection 

    Default

    param
     

    batchsize

    $batchsize 

    Default

     

    count

    $count 

    Default

     

    limit

    $limit 

    Default

     Constants

     

    documents array index

    ENTRY_GRAPH = 'graph' 
     

    example parameter

    KEY_FROM = '_from' 
     

    example parameter

    KEY_TO = '_to' 
     

    collection parameter

    OPTION_COLLECTION = 'collection' 
     

    collections parameter

    OPTION_COLLECTIONS = 'collections' 
     

    drop collection

    OPTION_DROP_COLLECTION = 'dropCollection' 
     

    direction parameter

    OPTION_EDGES = 'edges' 
     

    edge definition parameter

    OPTION_EDGE_DEFINITION = 'edgeDefinition' 
     

    edge definitions parameter

    OPTION_EDGE_DEFINITIONS = 'edgeDefinitions' 
     

    direction parameter

    OPTION_KEY = '_key' 
     

    name parameter

    OPTION_NAME = 'name' 
     

    orphan collection parameter

    OPTION_ORPHAN_COLLECTIONS = 'orphanCollections' 
     

    conditional update of edges or vertices

    OPTION_REVISION = 'revision' 
     

    vertex parameter

    OPTION_VERTICES = 'vertices'