1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\FluentAQL\AQL; |
6
|
|
|
|
7
|
|
|
use LaravelFreelancerNL\FluentAQL\Expressions\Expression; |
8
|
|
|
use LaravelFreelancerNL\FluentAQL\Expressions\FunctionExpression; |
9
|
|
|
use LaravelFreelancerNL\FluentAQL\Expressions\ListExpression; |
10
|
|
|
use LaravelFreelancerNL\FluentAQL\QueryBuilder; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Trait hasFunctions. |
14
|
|
|
* |
15
|
|
|
* Miscellaneous AQL functions. |
16
|
|
|
* |
17
|
|
|
* @see https://www.arangodb.com/docs/stable/aql/functions-miscellaneous.html |
18
|
|
|
*/ |
19
|
|
|
trait HasMiscellaneousFunctions |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Throws an error if the given predicate fails. |
23
|
|
|
* |
24
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-miscellaneous.html#assert--warn |
25
|
|
|
*/ |
26
|
2 |
|
public function assert(): FunctionExpression |
27
|
|
|
{ |
28
|
2 |
|
$arguments = func_get_args(); |
29
|
|
|
|
30
|
|
|
/** @var string $errorMessage */ |
31
|
2 |
|
$errorMessage = array_pop($arguments); |
32
|
|
|
|
33
|
2 |
|
$predicates = $arguments; |
34
|
2 |
|
if (! is_array($predicates[0])) { |
35
|
1 |
|
$predicates = [[ |
36
|
|
|
...$predicates |
37
|
|
|
]]; |
38
|
|
|
} |
39
|
2 |
|
$preppedArguments = [ |
40
|
|
|
'predicates' => $predicates, |
41
|
|
|
'errorMessage' => $errorMessage |
42
|
|
|
]; |
43
|
|
|
|
44
|
2 |
|
return new FunctionExpression('ASSERT', $preppedArguments); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Return one or more specific documents from a collection. |
49
|
|
|
* |
50
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-miscellaneous.html#document |
51
|
|
|
* |
52
|
|
|
* @param string|array<mixed>|QueryBuilder|Expression $collection |
53
|
|
|
* @param string|array<mixed>|QueryBuilder|Expression|null $id |
54
|
|
|
*/ |
55
|
1 |
|
public function document( |
56
|
|
|
string|array|QueryBuilder|Expression $collection, |
57
|
|
|
string|array|QueryBuilder|Expression $id = null |
58
|
|
|
): FunctionExpression { |
59
|
1 |
|
return new FunctionExpression('DOCUMENT', ['collection' => $collection, 'id' => $id]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Returns the name of the current database. |
65
|
|
|
* |
66
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-miscellaneous.html#current_database |
67
|
|
|
* |
68
|
|
|
* @return FunctionExpression |
69
|
|
|
*/ |
70
|
1 |
|
public function currentDatabase() |
71
|
|
|
{ |
72
|
1 |
|
return new FunctionExpression('CURRENT_DATABASE'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Return the name of the current user. |
77
|
|
|
* |
78
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-miscellaneous.html#current_user |
79
|
|
|
* |
80
|
|
|
* @return FunctionExpression |
81
|
|
|
*/ |
82
|
1 |
|
public function currentUser() |
83
|
|
|
{ |
84
|
1 |
|
return new FunctionExpression('CURRENT_USER'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Return the first alternative that is a document, and null if none of the alternatives is a document. |
89
|
|
|
* |
90
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-miscellaneous.html#first_document |
91
|
|
|
* |
92
|
|
|
* @param mixed $arguments |
93
|
|
|
* |
94
|
|
|
* @return FunctionExpression |
95
|
|
|
*/ |
96
|
1 |
|
public function firstDocument(...$arguments) |
97
|
|
|
{ |
98
|
1 |
|
return new FunctionExpression('FIRST_DOCUMENT', $arguments); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Returns false and gives a warning if the given predicate fails. |
103
|
|
|
* |
104
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-miscellaneous.html#assert--warn |
105
|
|
|
*/ |
106
|
2 |
|
public function warn(): FunctionExpression |
107
|
|
|
{ |
108
|
2 |
|
$arguments = func_get_args(); |
109
|
|
|
|
110
|
|
|
/** @var string $errorMessage */ |
111
|
2 |
|
$errorMessage = array_pop($arguments); |
112
|
|
|
|
113
|
2 |
|
$predicates = $arguments; |
114
|
2 |
|
if (! is_array($predicates[0])) { |
115
|
1 |
|
$predicates = [[ |
116
|
|
|
...$predicates |
117
|
|
|
]]; |
118
|
|
|
} |
119
|
2 |
|
$preppedArguments = [ |
120
|
|
|
'predicates' => $predicates, |
121
|
|
|
'errorMessage' => $errorMessage |
122
|
|
|
]; |
123
|
|
|
|
124
|
2 |
|
return new FunctionExpression('WARN', $preppedArguments); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|