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\QueryBuilder; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Geo AQL functions. |
13
|
|
|
* |
14
|
|
|
* @see https://www.arangodb.com/docs/stable/aql/functions-string.html |
15
|
|
|
*/ |
16
|
|
|
trait HasStringFunctions |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Concatenate the values passed as value1 to valueN. |
20
|
|
|
* |
21
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#concat |
22
|
|
|
*/ |
23
|
1 |
|
public function concat( |
24
|
|
|
string|object ...$arguments |
25
|
|
|
): FunctionExpression { |
26
|
1 |
|
return new FunctionExpression('CONCAT', $arguments); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Concatenate the strings passed as arguments value1 to valueN using the separator string. |
31
|
|
|
* |
32
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#concat_separator |
33
|
|
|
* |
34
|
|
|
* @param string|Expression|QueryBuilder $separator |
35
|
|
|
* @param array<int, string|array<string>|Expression|QueryBuilder> ...$values |
36
|
|
|
* @return FunctionExpression |
37
|
|
|
*/ |
38
|
1 |
|
public function concatSeparator( |
39
|
|
|
string|Expression|QueryBuilder $separator, |
40
|
|
|
string|array|Expression|QueryBuilder ...$values |
41
|
|
|
): FunctionExpression { |
42
|
1 |
|
$arguments = array_merge([$separator], $values); |
43
|
|
|
|
44
|
1 |
|
return new FunctionExpression('CONCAT_SEPARATOR', $arguments); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Check whether the string search is contained in the string text. |
49
|
|
|
* |
50
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#contains |
51
|
|
|
* |
52
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
53
|
|
|
*/ |
54
|
3 |
|
public function contains( |
55
|
|
|
string|object $text, |
56
|
|
|
string|object $search, |
57
|
|
|
bool|object $returnIndex = false |
58
|
|
|
): FunctionExpression { |
59
|
3 |
|
return new FunctionExpression('CONTAINS', [$text, $search, $returnIndex]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Return the position of the first occurrence of the string search inside the string text. Positions start at 0. |
64
|
|
|
* |
65
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#find_first |
66
|
|
|
*/ |
67
|
3 |
|
public function findFirst( |
68
|
|
|
string|object $text, |
69
|
|
|
string|object $search, |
70
|
|
|
int|object $start = null, |
71
|
|
|
int|object $end = null |
72
|
|
|
): FunctionExpression { |
73
|
3 |
|
$arguments = [ |
74
|
3 |
|
'text' => $text, |
75
|
3 |
|
'search' => $search, |
76
|
|
|
]; |
77
|
3 |
|
if (isset($start)) { |
78
|
2 |
|
$arguments['start'] = $start; |
79
|
|
|
} |
80
|
3 |
|
if (isset($end)) { |
81
|
1 |
|
$arguments['end'] = $end; |
82
|
|
|
} |
83
|
|
|
|
84
|
3 |
|
return new FunctionExpression('FIND_FIRST', $arguments); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Return the position of the last occurrence of the string search inside the string text. Positions start at 0. |
90
|
|
|
* |
91
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#find_last |
92
|
|
|
*/ |
93
|
3 |
|
public function findLast( |
94
|
|
|
string|object $text, |
95
|
|
|
string|object $search, |
96
|
|
|
int|object $start = null, |
97
|
|
|
int|object $end = null |
98
|
|
|
): FunctionExpression { |
99
|
3 |
|
$arguments = [ |
100
|
3 |
|
'text' => $text, |
101
|
3 |
|
'search' => $search, |
102
|
|
|
]; |
103
|
3 |
|
if (isset($start)) { |
104
|
2 |
|
$arguments['start'] = $start; |
105
|
|
|
} |
106
|
3 |
|
if (isset($end)) { |
107
|
1 |
|
$arguments['end'] = $end; |
108
|
|
|
} |
109
|
|
|
|
110
|
3 |
|
return new FunctionExpression('FIND_LAST', $arguments); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Calculate the Damerau-Levenshtein distance between two strings. |
115
|
|
|
* |
116
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#levenshtein_distance |
117
|
|
|
*/ |
118
|
1 |
|
public function levenshteinDistance( |
119
|
|
|
string|object $value1, |
120
|
|
|
string|object $value2 |
121
|
|
|
): FunctionExpression { |
122
|
1 |
|
return new FunctionExpression('LEVENSHTEIN_DISTANCE', [$value1, $value2]); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Convert upper-case letters in value to their lower-case counterparts. |
127
|
|
|
* |
128
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#lower |
129
|
|
|
*/ |
130
|
1 |
|
public function lower( |
131
|
|
|
string|object $value, |
132
|
|
|
): FunctionExpression { |
133
|
1 |
|
return new FunctionExpression('LOWER', [$value]); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Return the string value with whitespace (or supplied characters) stripped from the start. |
138
|
|
|
* |
139
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#ltrim |
140
|
|
|
*/ |
141
|
2 |
|
public function ltrim( |
142
|
|
|
string|object $value, |
143
|
|
|
null|string|object $char = null |
144
|
|
|
): FunctionExpression { |
145
|
2 |
|
$arguments = [ |
146
|
2 |
|
'value' => $value, |
147
|
2 |
|
'char' => $char, |
148
|
|
|
]; |
149
|
|
|
|
150
|
2 |
|
return new FunctionExpression('LTRIM', $arguments); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Check whether the string search is contained in the string text. |
155
|
|
|
* |
156
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#contains |
157
|
|
|
* |
158
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
159
|
|
|
*/ |
160
|
1 |
|
public function regexMatches( |
161
|
|
|
string|object $text, |
162
|
|
|
string|object $regex, |
163
|
|
|
bool|object $caseInsensitive = false |
164
|
|
|
): FunctionExpression { |
165
|
1 |
|
return new FunctionExpression('REGEX_MATCHES', [$text, $regex, $caseInsensitive]); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Replace the pattern search with the string replacement in the string text, using regular expression matching. |
170
|
|
|
* |
171
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#regex_replace |
172
|
|
|
* |
173
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
174
|
|
|
*/ |
175
|
1 |
|
public function regexReplace( |
176
|
|
|
string|object $text, |
177
|
|
|
string|object $regex, |
178
|
|
|
string|object $replacement, |
179
|
|
|
bool|object $caseInsensitive = false |
180
|
|
|
): FunctionExpression { |
181
|
1 |
|
return new FunctionExpression('REGEX_REPLACE', [$text, $regex, $replacement, $caseInsensitive]); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Split the given string text into a list of strings, using the separator. |
186
|
|
|
* |
187
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#regex_split |
188
|
|
|
* |
189
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
190
|
|
|
*/ |
191
|
1 |
|
public function regexSplit( |
192
|
|
|
string|object $text, |
193
|
|
|
string|object $splitExpression, |
194
|
|
|
bool|object $caseInsensitive = false, |
195
|
|
|
int|object $limit = null |
196
|
|
|
): FunctionExpression { |
197
|
1 |
|
$arguments = [ |
198
|
1 |
|
'text' => $text, |
199
|
1 |
|
'splitExpression' => $splitExpression, |
200
|
1 |
|
'caseInsensitive' => $caseInsensitive |
201
|
|
|
]; |
202
|
1 |
|
if (isset($limit)) { |
203
|
1 |
|
$arguments['limit'] = $limit; |
204
|
|
|
} |
205
|
|
|
|
206
|
1 |
|
return new FunctionExpression('REGEX_SPLIT', $arguments); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Check whether the pattern search is contained in the string text, using regular expression matching. |
211
|
|
|
* |
212
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#regex_test |
213
|
|
|
* |
214
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
215
|
|
|
*/ |
216
|
1 |
|
public function regexTest( |
217
|
|
|
string|object $text, |
218
|
|
|
string|object $search, |
219
|
|
|
bool|object $caseInsensitive = false |
220
|
|
|
): FunctionExpression { |
221
|
1 |
|
return new FunctionExpression('REGEX_TEST', [$text, $search, $caseInsensitive]); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Return the string value with whitespace (or supplied characters) stripped from the end. |
226
|
|
|
* |
227
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#rtrim |
228
|
|
|
*/ |
229
|
2 |
|
public function rtrim( |
230
|
|
|
string|object $value, |
231
|
|
|
null|string|object $char = null |
232
|
|
|
): FunctionExpression { |
233
|
2 |
|
$arguments = [ |
234
|
2 |
|
'value' => $value, |
235
|
2 |
|
'char' => $char, |
236
|
|
|
]; |
237
|
|
|
|
238
|
2 |
|
return new FunctionExpression('RTRIM', $arguments); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Return the soundex fingerprint of value. |
243
|
|
|
* |
244
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#soundex |
245
|
|
|
*/ |
246
|
1 |
|
public function soundex( |
247
|
|
|
string|object $value, |
248
|
|
|
): FunctionExpression { |
249
|
1 |
|
return new FunctionExpression('SOUNDEX', [$value]); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Split the given string text into a list of strings, using the separator. |
254
|
|
|
* |
255
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#regex_split |
256
|
|
|
* |
257
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
258
|
|
|
*/ |
259
|
1 |
|
public function split( |
260
|
|
|
string|object $value, |
261
|
|
|
string|object $separator, |
262
|
|
|
int|object $limit = null |
263
|
|
|
): FunctionExpression { |
264
|
1 |
|
$arguments = [ |
265
|
1 |
|
'value' => $value, |
266
|
1 |
|
'separator' => $separator, |
267
|
|
|
]; |
268
|
1 |
|
if (isset($limit)) { |
269
|
1 |
|
$arguments['limit'] = $limit; |
270
|
|
|
} |
271
|
|
|
|
272
|
1 |
|
return new FunctionExpression('SPLIT', $arguments); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Replace search values in the string value. |
277
|
|
|
* |
278
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#substitute |
279
|
|
|
* |
280
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
281
|
|
|
* @param string|array<mixed>|object $search |
282
|
|
|
* @param string|array<mixed>|object $replace |
283
|
|
|
*/ |
284
|
1 |
|
public function substitute( |
285
|
|
|
string|object $value, |
286
|
|
|
string|array|object $search, |
287
|
|
|
string|array|object $replace, |
288
|
|
|
int|object $limit = null |
289
|
|
|
): FunctionExpression { |
290
|
1 |
|
$arguments = [ |
291
|
1 |
|
'value' => $value, |
292
|
1 |
|
'search' => $search, |
293
|
1 |
|
'replace' => $replace, |
294
|
|
|
]; |
295
|
1 |
|
if (isset($limit)) { |
296
|
1 |
|
$arguments['limit'] = $limit; |
297
|
|
|
} |
298
|
1 |
|
return new FunctionExpression('SUBSTITUTE', $arguments); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Return a substring of value. |
303
|
|
|
* |
304
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#substring |
305
|
|
|
*/ |
306
|
1 |
|
public function substring( |
307
|
|
|
string|object $value, |
308
|
|
|
int|object $offset, |
309
|
|
|
int|object $length = null |
310
|
|
|
): FunctionExpression { |
311
|
1 |
|
$arguments = [ |
312
|
1 |
|
'value' => $value, |
313
|
1 |
|
'offset' => $offset, |
314
|
|
|
]; |
315
|
1 |
|
if (isset($length)) { |
316
|
1 |
|
$arguments['length'] = $length; |
317
|
|
|
} |
318
|
|
|
|
319
|
1 |
|
return new FunctionExpression('SUBSTRING', $arguments); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Return a substring of value. |
324
|
|
|
* |
325
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#tokens |
326
|
|
|
*/ |
327
|
1 |
|
public function tokens( |
328
|
|
|
string|object $input, |
329
|
|
|
string|object $analyzer |
330
|
|
|
): FunctionExpression { |
331
|
1 |
|
return new FunctionExpression('TOKENS', [$input, $analyzer]); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Return the string value with whitespace stripped from the start and/or end. |
336
|
|
|
* |
337
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#trim |
338
|
|
|
*/ |
339
|
3 |
|
public function trim( |
340
|
|
|
string|object $value, |
341
|
|
|
null|string|int|object $type = null |
342
|
|
|
): FunctionExpression { |
343
|
3 |
|
$arguments = [ |
344
|
3 |
|
'value' => $value, |
345
|
3 |
|
'type' => $type, |
346
|
|
|
]; |
347
|
|
|
|
348
|
3 |
|
return new FunctionExpression('TRIM', $arguments); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* Convert lower-case letters in value to their upper-case counterparts. |
353
|
|
|
* |
354
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#upper |
355
|
|
|
*/ |
356
|
1 |
|
public function upper( |
357
|
|
|
string|object $value, |
358
|
|
|
): FunctionExpression { |
359
|
1 |
|
return new FunctionExpression('UPPER', [$value]); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* Return a universally unique identifier value. |
364
|
|
|
* |
365
|
|
|
* @link https://www.arangodb.com/docs/stable/aql/functions-string.html#uuid |
366
|
|
|
* |
367
|
|
|
* @return FunctionExpression |
368
|
|
|
*/ |
369
|
1 |
|
public function uuid() |
370
|
|
|
{ |
371
|
1 |
|
return new FunctionExpression('UUID'); |
372
|
|
|
} |
373
|
|
|
} |
374
|
|
|
|