1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\FluentAQL\AQL; |
6
|
|
|
|
7
|
|
|
use LaravelFreelancerNL\FluentAQL\Expressions\FunctionExpression; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Geo AQL functions. |
11
|
|
|
* |
12
|
|
|
* @see https://www.arangodb.com/docs/stable/aql/functions-string.html |
13
|
|
|
*/ |
14
|
|
|
trait HasStringFunctions |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Concatenate the values passed as value1 to valueN. |
18
|
|
|
* |
19
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#concat |
20
|
|
|
*/ |
21
|
1 |
|
public function concat( |
22
|
|
|
string|object ...$arguments |
23
|
|
|
): FunctionExpression { |
24
|
1 |
|
return new FunctionExpression('CONCAT', $arguments); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Concatenate the strings passed as arguments value1 to valueN using the separator string. |
29
|
|
|
* |
30
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#concat_separator |
31
|
|
|
*/ |
32
|
1 |
|
public function concatSeparator( |
33
|
|
|
string|object ...$arguments |
34
|
|
|
): FunctionExpression { |
35
|
1 |
|
return new FunctionExpression('CONCAT_SEPARATOR', $arguments); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Check whether the string search is contained in the string text. |
40
|
|
|
* |
41
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#contains |
42
|
|
|
* |
43
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
44
|
|
|
*/ |
45
|
2 |
|
public function contains( |
46
|
|
|
string|object $text, |
47
|
|
|
string|object $search, |
48
|
|
|
bool|object $returnIndex = false |
49
|
|
|
): FunctionExpression { |
50
|
2 |
|
return new FunctionExpression('CONTAINS', [$text, $search, $returnIndex]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Calculate the Damerau-Levenshtein distance between two strings. |
55
|
|
|
* |
56
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#levenshtein_distance |
57
|
|
|
*/ |
58
|
1 |
|
public function levenshteinDistance( |
59
|
|
|
string|object $value1, |
60
|
|
|
string|object $value2 |
61
|
|
|
): FunctionExpression { |
62
|
1 |
|
return new FunctionExpression('LEVENSHTEIN_DISTANCE', [$value1, $value2]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Convert upper-case letters in value to their lower-case counterparts. |
67
|
|
|
* |
68
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#lower |
69
|
|
|
*/ |
70
|
1 |
|
public function lower( |
71
|
|
|
string|object $value, |
72
|
|
|
): FunctionExpression { |
73
|
1 |
|
return new FunctionExpression('LOWER', [$value]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Check whether the string search is contained in the string text. |
78
|
|
|
* |
79
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#contains |
80
|
|
|
* |
81
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
82
|
|
|
*/ |
83
|
1 |
|
public function regexMatches( |
84
|
|
|
string|object $text, |
85
|
|
|
string|object $regex, |
86
|
|
|
bool|object $caseInsensitive = false |
87
|
|
|
): FunctionExpression { |
88
|
1 |
|
return new FunctionExpression('REGEX_MATCHES', [$text, $regex, $caseInsensitive]); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Replace the pattern search with the string replacement in the string text, using regular expression matching. |
93
|
|
|
* |
94
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#regex_replace |
95
|
|
|
* |
96
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
97
|
|
|
*/ |
98
|
1 |
|
public function regexReplace( |
99
|
|
|
string|object $text, |
100
|
|
|
string|object $regex, |
101
|
|
|
string|object $replacement, |
102
|
|
|
bool|object $caseInsensitive = false |
103
|
|
|
): FunctionExpression { |
104
|
1 |
|
return new FunctionExpression('REGEX_REPLACE', [$text, $regex, $replacement, $caseInsensitive]); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Split the given string text into a list of strings, using the separator. |
109
|
|
|
* |
110
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#regex_split |
111
|
|
|
* |
112
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
113
|
|
|
*/ |
114
|
1 |
|
public function regexSplit( |
115
|
|
|
string|object $text, |
116
|
|
|
string|object $splitExpression, |
117
|
|
|
bool|object $caseInsensitive = false, |
118
|
|
|
int|object $limit = null |
119
|
|
|
): FunctionExpression { |
120
|
1 |
|
$arguments = [ |
121
|
1 |
|
'text' => $text, |
122
|
1 |
|
'splitExpression' => $splitExpression, |
123
|
1 |
|
'caseInsensitive' => $caseInsensitive |
124
|
|
|
]; |
125
|
1 |
|
if (isset($limit)) { |
126
|
1 |
|
$arguments['limit'] = $limit; |
127
|
|
|
} |
128
|
|
|
|
129
|
1 |
|
return new FunctionExpression('REGEX_SPLIT', $arguments); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Check whether the pattern search is contained in the string text, using regular expression matching. |
134
|
|
|
* |
135
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#regex_test |
136
|
|
|
* |
137
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
138
|
|
|
*/ |
139
|
1 |
|
public function regexTest( |
140
|
|
|
string|object $text, |
141
|
|
|
string|object $search, |
142
|
|
|
bool|object $caseInsensitive = false |
143
|
|
|
): FunctionExpression { |
144
|
1 |
|
return new FunctionExpression('REGEX_TEST', [$text, $search, $caseInsensitive]); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Split the given string text into a list of strings, using the separator. |
149
|
|
|
* |
150
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#regex_split |
151
|
|
|
* |
152
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
153
|
|
|
*/ |
154
|
1 |
|
public function split( |
155
|
|
|
string|object $value, |
156
|
|
|
string|object $separator, |
157
|
|
|
int|object $limit = null |
158
|
|
|
): FunctionExpression { |
159
|
1 |
|
$arguments = [ |
160
|
1 |
|
'value' => $value, |
161
|
1 |
|
'separator' => $separator, |
162
|
|
|
]; |
163
|
1 |
|
if (isset($limit)) { |
164
|
1 |
|
$arguments['limit'] = $limit; |
165
|
|
|
} |
166
|
|
|
|
167
|
1 |
|
return new FunctionExpression('SPLIT', $arguments); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Replace search values in the string value. |
172
|
|
|
* |
173
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#substitute |
174
|
|
|
* |
175
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
176
|
|
|
* @param string|array<mixed>|object $search |
177
|
|
|
* @param string|array<mixed>|object $replace |
178
|
|
|
*/ |
179
|
1 |
|
public function substitute( |
180
|
|
|
string|object $value, |
181
|
|
|
string|array|object $search, |
182
|
|
|
string|array|object $replace, |
183
|
|
|
int|object $limit = null |
184
|
|
|
): FunctionExpression { |
185
|
1 |
|
$arguments = [ |
186
|
1 |
|
'value' => $value, |
187
|
1 |
|
'search' => $search, |
188
|
1 |
|
'replace' => $replace, |
189
|
|
|
]; |
190
|
1 |
|
if (isset($limit)) { |
191
|
1 |
|
$arguments['limit'] = $limit; |
192
|
|
|
} |
193
|
1 |
|
return new FunctionExpression('SUBSTITUTE', $arguments); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Return a substring of value. |
198
|
|
|
* |
199
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#substring |
200
|
|
|
*/ |
201
|
1 |
|
public function substring( |
202
|
|
|
string|object $value, |
203
|
|
|
int|object $offset, |
204
|
|
|
int|object $length = null |
205
|
|
|
): FunctionExpression { |
206
|
1 |
|
$arguments = [ |
207
|
1 |
|
'value' => $value, |
208
|
1 |
|
'offset' => $offset, |
209
|
|
|
]; |
210
|
1 |
|
if (isset($length)) { |
211
|
1 |
|
$arguments['length'] = $length; |
212
|
|
|
} |
213
|
|
|
|
214
|
1 |
|
return new FunctionExpression('SUBSTRING', $arguments); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Return a substring of value. |
219
|
|
|
* |
220
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#tokens |
221
|
|
|
*/ |
222
|
1 |
|
public function tokens( |
223
|
|
|
string|object $input, |
224
|
|
|
string|object $analyzer |
225
|
|
|
): FunctionExpression { |
226
|
1 |
|
return new FunctionExpression('TOKENS', [$input, $analyzer]); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Return the string value with whitespace stripped from the start and/or end. |
231
|
|
|
* |
232
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#trim |
233
|
|
|
*/ |
234
|
1 |
|
public function trim( |
235
|
|
|
string|object $value, |
236
|
|
|
int|object $type |
237
|
|
|
): FunctionExpression { |
238
|
1 |
|
$arguments = [ |
239
|
1 |
|
'value' => $value, |
240
|
1 |
|
'type' => $type, |
241
|
|
|
]; |
242
|
|
|
|
243
|
1 |
|
return new FunctionExpression('TRIM', $arguments); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Convert lower-case letters in value to their upper-case counterparts. |
248
|
|
|
* |
249
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#upper |
250
|
|
|
*/ |
251
|
1 |
|
public function upper( |
252
|
|
|
string|object $value, |
253
|
|
|
): FunctionExpression { |
254
|
1 |
|
return new FunctionExpression('UPPER', [$value]); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Return a universally unique identifier value. |
259
|
|
|
* |
260
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#uuid |
261
|
|
|
* |
262
|
|
|
* @return FunctionExpression |
263
|
|
|
*/ |
264
|
1 |
|
public function uuid() |
265
|
|
|
{ |
266
|
1 |
|
return new FunctionExpression('UUID'); |
267
|
|
|
} |
268
|
|
|
} |
269
|
|
|
|