LaravelFreelancerNL /
fluentaql
| 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-geo.html |
||
| 15 | */ |
||
| 16 | trait HasDocumentFunctions |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Return the top-level attribute keys of the document as an array. |
||
| 20 | * |
||
| 21 | * @link https://www.arangodb.com/docs/stable/aql/functions-document.html#attributes |
||
| 22 | * |
||
| 23 | * @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
||
| 24 | */ |
||
| 25 | 1 | public function attributes( |
|
| 26 | string|object $document, |
||
| 27 | bool|object $removeInternal = false, |
||
| 28 | bool|object $sort = false |
||
| 29 | ): FunctionExpression { |
||
| 30 | 1 | return new FunctionExpression('ATTRIBUTES', [ |
|
| 31 | 'document' => $document, |
||
| 32 | 'removeInternal' => $removeInternal, |
||
| 33 | 'sort' => $sort, |
||
| 34 | ]); |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Keep only the defined attributes of the document. |
||
| 39 | * All other attributes will be removed from the result. |
||
| 40 | * |
||
| 41 | * @link https://www.arangodb.com/docs/stable/aql/functions-document.html#keep |
||
| 42 | * |
||
| 43 | * @param string|array<mixed>|object $document |
||
| 44 | * @param string|array<mixed>|object $attributes |
||
| 45 | */ |
||
| 46 | 2 | public function keepAttributes( |
|
| 47 | string|array|object $document, |
||
| 48 | string|array|object $attributes |
||
| 49 | ): FunctionExpression { |
||
| 50 | 2 | if (! is_array($attributes)) { |
|
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 51 | 1 | $attributes = [$attributes]; |
|
| 52 | } |
||
| 53 | |||
| 54 | 2 | $arguments = [ |
|
| 55 | "document" => $document, |
||
| 56 | "attributes" => $attributes, |
||
| 57 | ]; |
||
| 58 | 2 | return new FunctionExpression('KEEP', $arguments); |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Compare the given document against each example document provided. |
||
| 63 | * |
||
| 64 | * @link https://www.arangodb.com/docs/stable/aql/functions-document.html#matches |
||
| 65 | * |
||
| 66 | * @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
||
| 67 | * |
||
| 68 | * @param array<mixed>|object $document |
||
| 69 | * @param array<mixed>|object $examples |
||
| 70 | * @param bool|QueryBuilder|Expression $returnIndex |
||
| 71 | * @return FunctionExpression |
||
| 72 | */ |
||
| 73 | 1 | public function matches( |
|
| 74 | array|object $document, |
||
| 75 | array|object $examples, |
||
| 76 | bool|QueryBuilder|Expression $returnIndex = false |
||
| 77 | ): FunctionExpression { |
||
| 78 | 1 | $arguments = [ |
|
| 79 | "document" => $document, |
||
| 80 | "examples" => $examples, |
||
| 81 | "returnIndex" => $returnIndex, |
||
| 82 | ]; |
||
| 83 | |||
| 84 | 1 | return new FunctionExpression('MATCHES', $arguments); |
|
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Merge the documents document1 to documentN into a single document. |
||
| 89 | * |
||
| 90 | * @link https://www.arangodb.com/docs/stable/aql/functions-document.html#merge |
||
| 91 | * |
||
| 92 | * @param array<mixed>|string|Expression $documents |
||
| 93 | * @return FunctionExpression |
||
| 94 | */ |
||
| 95 | 3 | public function merge(string|array|Expression ...$documents): FunctionExpression |
|
| 96 | { |
||
| 97 | 3 | return new FunctionExpression('MERGE', $documents); |
|
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Compare the given document against each example document provided. |
||
| 102 | * |
||
| 103 | * @link https://www.arangodb.com/docs/stable/aql/functions-document.html#parse_identifier |
||
| 104 | * |
||
| 105 | * @param string|object $documentHandle |
||
| 106 | * @return FunctionExpression |
||
| 107 | */ |
||
| 108 | 1 | public function parseIdentifier(mixed $documentHandle): FunctionExpression |
|
| 109 | { |
||
| 110 | 1 | return new FunctionExpression('PARSE_IDENTIFIER', [$documentHandle]); |
|
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Remove attributes from document. |
||
| 115 | * |
||
| 116 | * @link https://www.arangodb.com/docs/stable/aql/functions-document.html#unset |
||
| 117 | * |
||
| 118 | * @param string|array<mixed>|object $attributes |
||
| 119 | */ |
||
| 120 | 2 | public function unset( |
|
| 121 | string|object $document, |
||
| 122 | string|array|object $attributes |
||
| 123 | ): FunctionExpression { |
||
| 124 | 2 | if (! is_array($attributes)) { |
|
|
0 ignored issues
–
show
|
|||
| 125 | 1 | $attributes = [$attributes]; |
|
| 126 | } |
||
| 127 | |||
| 128 | 2 | $arguments = [ |
|
| 129 | "document" => $document, |
||
| 130 | "attributes" => $attributes, |
||
| 131 | ]; |
||
| 132 | 2 | return new FunctionExpression('UNSET', $arguments); |
|
| 133 | } |
||
| 134 | } |
||
| 135 |