Skip to content

Commit

Permalink
added some SmartGraph support
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteemann committed Jan 11, 2022
1 parent 00988a4 commit 2230af9
Show file tree
Hide file tree
Showing 5 changed files with 601 additions and 17 deletions.
62 changes: 52 additions & 10 deletions lib/ArangoDBClient/EdgeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,32 @@ class EdgeDefinition
* @var array names of the end vertices collection
*/
protected $_toCollections = [];

/**
* An array containing satellite collections in Hybrid SmartGraphs
*
* @var array satellite collections
*/
protected $_satellites = [];

/**
* Constructs an new edge definition
*
* @param string $relation - name of the relation (the underlying edge collection).
* @param array|string $fromCollections - a list of collections providing the edges start vertices or a string holding a single collection name.
* @param array|string $toCollections - a list of collections providing the edges end vertices or a string holding a single collection name.
* @param array|string $satellites - a list of satellite collections (SmartGraph only).
*
* @since 2.2
*
*/
public function __construct($relation = null, $fromCollections = [], $toCollections = [])
public function __construct($relation = null, $fromCollections = [], $toCollections = [], $satellites = [])
{
$this->_relation = $relation;

$fromCollections = (array) $fromCollections;
$toCollections = (array) $toCollections;

$this->_fromCollections = $fromCollections;
$this->_toCollections = $toCollections;
$this->_fromCollections = (array) $fromCollections;
$this->_toCollections = (array) $toCollections;
$this->_satellites = (array) $satellites;
}

/**
Expand Down Expand Up @@ -111,6 +117,17 @@ public function getFromCollections()
{
return $this->_fromCollections;
}

/**
* Get the 'satellites' collections of the graph.
*
* @return array
* @since 3.9
*/
public function getSatellites()
{
return $this->_satellites;
}

/**
* Add a 'to' collections of the graph.
Expand All @@ -135,6 +152,18 @@ public function addFromCollection($fromCollection)
{
$this->_fromCollections[] = $fromCollection;
}

/**
* Add a 'satellite' collection of the graph.
*
* @param string $toCollection - the name of the added collection.
*
* @since 3.9
*/
public function addSatelliteCollection($collection)
{
$this->_satellites[] = $collection;
}

/**
* Resets the 'to' collections of the graph.
Expand All @@ -155,6 +184,16 @@ public function clearFromCollection()
{
return $this->_fromCollections = [];
}

/**
* Resets the 'satellites' collections of the graph.
*
* @since 3.9
*/
public function clearSatellites()
{
return $this->_satellites = [];
}

/**
* Transforms an edge definition to an array.
Expand All @@ -168,6 +207,7 @@ public function transformToArray()
$transformedEd['collection'] = $this->getRelation();
$transformedEd['from'] = $this->getFromCollections();
$transformedEd['to'] = $this->getToCollections();
$transformedEd['satellites'] = $this->getSatellites();

return $transformedEd;
}
Expand All @@ -179,13 +219,14 @@ public function transformToArray()
*
* @param string $relation - name of the relation (the underlying edge collection).
* @param array $vertexCollections - a list of collections providing the edges start and end vertices.
* @param array $satellites - a list of satellite collections (for Hybrid SmartGraphs).
*
* @return EdgeDefinition
* @since 2.2
*/
public static function createUndirectedRelation($relation, $vertexCollections)
public static function createUndirectedRelation($relation, $vertexCollections, array $satellites = [])
{
return new EdgeDefinition($relation, $vertexCollections, $vertexCollections);
return new EdgeDefinition($relation, $vertexCollections, $vertexCollections, $satellites);
}


Expand All @@ -196,13 +237,14 @@ public static function createUndirectedRelation($relation, $vertexCollections)
* @param string $relation - name of the relation (the underlying edge collection).
* @param array|string $fromCollections - a list of collections providing the edges start vertices or a string holding a single collection name.
* @param array|string $toCollections - a list of collections providing the edges end vertices or a string holding a single collection name.
* @param array|string $satellites - a list of satellite collections (for Hybrid SmartGraphs).
*
* @return EdgeDefinition
* @since 2.2
*/
public static function createDirectedRelation($relation, $fromCollections, $toCollections)
public static function createDirectedRelation($relation, $fromCollections, $toCollections, array $satellites = [])
{
return new EdgeDefinition($relation, $fromCollections, $toCollections);
return new EdgeDefinition($relation, $fromCollections, $toCollections, $satellites);
}

}
Expand Down
Loading

0 comments on commit 2230af9

Please sign in to comment.