|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LaravelFreelancerNL\FluentAQL\AQL; |
|
4
|
|
|
|
|
5
|
|
|
use LaravelFreelancerNL\FluentAQL\Clauses\EdgeCollectionsClause; |
|
6
|
|
|
use LaravelFreelancerNL\FluentAQL\Clauses\GraphClause; |
|
7
|
|
|
use LaravelFreelancerNL\FluentAQL\Clauses\PruneClause; |
|
8
|
|
|
use LaravelFreelancerNL\FluentAQL\Clauses\TraverseClause; |
|
9
|
|
|
use LaravelFreelancerNL\FluentAQL\Clauses\TraverseKShortestPathClause; |
|
10
|
|
|
use LaravelFreelancerNL\FluentAQL\Clauses\TraverseShortestPathClause; |
|
11
|
|
|
use LaravelFreelancerNL\FluentAQL\Clauses\WithClause; |
|
12
|
|
|
use LaravelFreelancerNL\FluentAQL\QueryBuilder; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Trait hasGraphClauses |
|
16
|
|
|
* API calls to add clause commands to the builder. |
|
17
|
|
|
*/ |
|
18
|
|
|
trait HasGraphClauses |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
abstract public function addCommand($command); |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Start a query with 'WITH' to prevent graph traversal deadlocks. |
|
25
|
|
|
* This is required in clusters. |
|
26
|
|
|
* |
|
27
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/operations-with.html |
|
28
|
|
|
* |
|
29
|
|
|
* @return QueryBuilder |
|
30
|
|
|
*/ |
|
31
|
|
|
public function with(): self |
|
32
|
|
|
{ |
|
33
|
|
|
$this->addCommand(new WithClause(func_get_args())); |
|
34
|
|
|
|
|
35
|
|
|
return $this; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Traverse a graph |
|
40
|
|
|
* Must be preceded by a FOR clause. |
|
41
|
|
|
* |
|
42
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/graphs-traversals.html |
|
43
|
|
|
* |
|
44
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
|
45
|
|
|
* |
|
46
|
|
|
* @param $fromVertex |
|
47
|
|
|
* @param string $inDirection |
|
48
|
|
|
* @return QueryBuilder |
|
49
|
|
|
*/ |
|
50
|
|
|
public function traverse( |
|
51
|
|
|
$fromVertex, |
|
52
|
|
|
$inDirection = 'outbound' |
|
53
|
|
|
): self { |
|
54
|
|
|
$this->addCommand(new TraverseClause($fromVertex, $inDirection)); |
|
55
|
|
|
|
|
56
|
|
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Shortest path alias for traverse. |
|
61
|
|
|
* |
|
62
|
|
|
* @link arangodb.com/docs/stable/aql/graphs-shortest-path.html |
|
63
|
|
|
* |
|
64
|
|
|
* @param $fromVertex |
|
65
|
|
|
* @param string $inDirection |
|
66
|
|
|
* @param string $toVertex |
|
67
|
|
|
* |
|
68
|
|
|
* @return QueryBuilder |
|
69
|
|
|
*/ |
|
70
|
|
|
public function shortestPath($fromVertex, $inDirection, $toVertex): self |
|
71
|
|
|
{ |
|
72
|
|
|
$this->addCommand(new TraverseShortestPathClause($fromVertex, $inDirection, $toVertex)); |
|
73
|
|
|
|
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* K Shortest Paths alias for traverse. |
|
79
|
|
|
* |
|
80
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/graphs-kshortest-paths.html |
|
81
|
|
|
* |
|
82
|
|
|
* @param $fromVertex |
|
83
|
|
|
* @param string $inDirection |
|
84
|
|
|
* @param string $toVertex |
|
85
|
|
|
* |
|
86
|
|
|
* @return QueryBuilder |
|
87
|
|
|
*/ |
|
88
|
|
|
public function kShortestPaths($fromVertex, $inDirection, $toVertex): self |
|
89
|
|
|
{ |
|
90
|
|
|
$this->addCommand(new TraverseKShortestPathClause($fromVertex, $inDirection, $toVertex)); |
|
91
|
|
|
|
|
92
|
|
|
return $this; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Named Graph clause |
|
97
|
|
|
* Only usable after traverse/shortestPath/kShortestPaths Clauses. |
|
98
|
|
|
* |
|
99
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/graphs-traversals.html |
|
100
|
|
|
* |
|
101
|
|
|
* @param string $graphName |
|
102
|
|
|
* |
|
103
|
|
|
* @return QueryBuilder |
|
104
|
|
|
*/ |
|
105
|
|
|
public function graph(string $graphName): self |
|
106
|
|
|
{ |
|
107
|
|
|
$this->addCommand(new GraphClause($graphName)); |
|
108
|
|
|
|
|
109
|
|
|
return $this; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* EdgeCollections Clause for unnamed graphs |
|
114
|
|
|
* Generates a list of edge collections to traverse through. |
|
115
|
|
|
* Only usable after traverse/shortestPath/kShortestPaths Clauses. |
|
116
|
|
|
* |
|
117
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/graphs-traversals.html |
|
118
|
|
|
* |
|
119
|
|
|
* @param array $edgeCollections |
|
120
|
|
|
* @return QueryBuilder |
|
121
|
|
|
*/ |
|
122
|
|
|
public function edgeCollections(...$edgeCollections): self |
|
123
|
|
|
{ |
|
124
|
|
|
$this->addCommand(new EdgeCollectionsClause($edgeCollections)); |
|
125
|
|
|
|
|
126
|
|
|
return $this; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Prune a graph traversal. |
|
131
|
|
|
* |
|
132
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/graphs-traversals.html#pruning |
|
133
|
|
|
* |
|
134
|
|
|
* @param $leftOperand |
|
135
|
|
|
* @param string $comparisonOperator |
|
136
|
|
|
* @param null $rightOperand |
|
|
|
|
|
|
137
|
|
|
* @param string $logicalOperator |
|
138
|
|
|
* |
|
139
|
|
|
* @return QueryBuilder |
|
140
|
|
|
*/ |
|
141
|
|
|
public function prune( |
|
142
|
|
|
$leftOperand, |
|
143
|
|
|
$comparisonOperator = null, |
|
144
|
|
|
$rightOperand = null, |
|
145
|
|
|
$logicalOperator = null |
|
146
|
|
|
): self { |
|
147
|
|
|
$predicates = $leftOperand; |
|
148
|
|
|
if (is_string($comparisonOperator)) { |
|
149
|
|
|
$predicates = [[$leftOperand, $comparisonOperator, $rightOperand, $logicalOperator]]; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
$this->addCommand(new PruneClause($predicates)); |
|
153
|
|
|
|
|
154
|
|
|
return $this; |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|