1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Query\Concerns; |
6
|
|
|
|
7
|
|
|
trait HandlesAqlGrammar |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Available predicate operators. |
11
|
|
|
* |
12
|
|
|
* @var array<string, int> |
13
|
|
|
*/ |
14
|
|
|
protected array $comparisonOperators = [ |
15
|
|
|
'==' => 1, |
16
|
|
|
'!=' => 1, |
17
|
|
|
'<' => 1, |
18
|
|
|
'>' => 1, |
19
|
|
|
'<=' => 1, |
20
|
|
|
'>=' => 1, |
21
|
|
|
'IN' => 1, |
22
|
|
|
'NOT IN' => 1, |
23
|
|
|
'LIKE' => 1, |
24
|
|
|
'~' => 1, |
25
|
|
|
'!~' => 1, |
26
|
|
|
'ALL ==' => 1, |
27
|
|
|
'ALL !=' => 1, |
28
|
|
|
'ALL <' => 1, |
29
|
|
|
'ALL >' => 1, |
30
|
|
|
'ALL <=' => 1, |
31
|
|
|
'ALL >=' => 1, |
32
|
|
|
'ALL IN' => 1, |
33
|
|
|
'ANY ==' => 1, |
34
|
|
|
'ANY !=' => 1, |
35
|
|
|
'ANY <' => 1, |
36
|
|
|
'ANY >' => 1, |
37
|
|
|
'ANY <=' => 1, |
38
|
|
|
'ANY >=' => 1, |
39
|
|
|
'ANY IN' => 1, |
40
|
|
|
'NONE ==' => 1, |
41
|
|
|
'NONE !=' => 1, |
42
|
|
|
'NONE <' => 1, |
43
|
|
|
'NONE >' => 1, |
44
|
|
|
'NONE <=' => 1, |
45
|
|
|
'NONE >=' => 1, |
46
|
|
|
'NONE IN' => 1, |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var array|int[] |
51
|
|
|
*/ |
52
|
|
|
protected array $arithmeticOperators = [ |
53
|
|
|
'+' => 1, |
54
|
|
|
'-' => 1, |
55
|
|
|
'*' => 1, |
56
|
|
|
'/' => 1, |
57
|
|
|
'%' => 1, |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var array|int[] |
62
|
|
|
*/ |
63
|
|
|
protected array $logicalOperators = [ |
64
|
|
|
'AND' => 1, |
65
|
|
|
'&&' => 1, |
66
|
|
|
'OR' => 1, |
67
|
|
|
'||' => 1, |
68
|
|
|
'NOT' => 1, |
69
|
|
|
'!' => 1, |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
protected string $rangeOperator = '..'; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get the format for database stored dates. |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function getDateFormat(): string |
80
|
|
|
{ |
81
|
|
|
return 'Y-m-d\TH:i:s.vp'; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get the appropriate query parameter place-holder for a value. |
86
|
|
|
* |
87
|
|
|
* @param mixed $value |
88
|
|
|
*/ |
89
|
|
|
public function parameter($value): string |
90
|
|
|
{ |
91
|
|
|
return $this->isExpression($value) ? $this->getValue($value) : (string) $value; |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Quote the given string literal. |
97
|
|
|
* |
98
|
|
|
* @param string|array $value |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function quoteString($value) |
102
|
|
|
{ |
103
|
|
|
if (is_array($value)) { |
104
|
|
|
return implode(', ', array_map([$this, __FUNCTION__], $value)); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return "`$value`"; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Wrap a table in keyword identifiers. |
112
|
|
|
* |
113
|
|
|
* @param \Illuminate\Database\Query\Expression|string $table |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function wrapTable($table) |
117
|
|
|
{ |
118
|
|
|
if (! $this->isExpression($table)) { |
119
|
|
|
return $this->tablePrefix.$table; |
120
|
|
|
// return $this->wrap($this->tablePrefix.$table, true); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return $this->getValue($table); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Wrap a single string in keyword identifiers. |
128
|
|
|
* |
129
|
|
|
* @param string $value |
130
|
|
|
* @return string |
131
|
|
|
*/ |
132
|
|
|
protected function wrapValue($value) |
133
|
|
|
{ |
134
|
|
|
if ($value === '*') { |
135
|
|
|
return $value; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
return '`'.str_replace('`', '``', $value).'`'; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
|
143
|
|
|
} |
144
|
|
|
|