1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace RulerZ\Target\Operators; |
6
|
|
|
|
7
|
|
|
class GenericSqlDefinitions |
8
|
|
|
{ |
9
|
|
|
public static function create(Definitions $customOperators): Definitions |
10
|
|
|
{ |
11
|
|
|
$defaultInlineOperators = [ |
12
|
|
|
'and' => function ($a, $b) { |
13
|
|
|
return sprintf('(%s AND %s)', $a, $b); |
14
|
|
|
}, |
15
|
|
|
'or' => function ($a, $b) { |
16
|
|
|
return sprintf('(%s OR %s)', $a, $b); |
17
|
|
|
}, |
18
|
|
|
'not' => function ($a) { |
19
|
|
|
return sprintf('NOT (%s)', $a); |
20
|
|
|
}, |
21
|
|
|
'=' => function ($a, $b) { |
22
|
|
|
return sprintf('%s = %s', $a, $b); |
23
|
|
|
}, |
24
|
|
|
'!=' => function ($a, $b) { |
25
|
|
|
return sprintf('%s != %s', $a, $b); |
26
|
|
|
}, |
27
|
|
|
'>' => function ($a, $b) { |
28
|
|
|
return sprintf('%s > %s', $a, $b); |
29
|
|
|
}, |
30
|
|
|
'>=' => function ($a, $b) { |
31
|
|
|
return sprintf('%s >= %s', $a, $b); |
32
|
|
|
}, |
33
|
|
|
'<' => function ($a, $b) { |
34
|
|
|
return sprintf('%s < %s', $a, $b); |
35
|
|
|
}, |
36
|
|
|
'<=' => function ($a, $b) { |
37
|
|
|
return sprintf('%s <= %s', $a, $b); |
38
|
|
|
}, |
39
|
|
|
'in' => function ($a, $b) { |
40
|
|
|
return sprintf('%s IN %s', $a, $b[0] === '(' ? $b : '('.$b.')'); |
41
|
|
|
}, |
42
|
|
|
'like' => function ($a, $b) { |
43
|
|
|
return sprintf('%s LIKE %s', $a, $b); |
44
|
|
|
}, |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
$definitions = new Definitions(); |
48
|
|
|
$definitions->defineInlineOperators($defaultInlineOperators); |
49
|
|
|
|
50
|
|
|
return $definitions->mergeWith($customOperators); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: