forked from kvnZero/hyperf-APIJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionCombineHandle.php
More file actions
55 lines (52 loc) · 1.84 KB
/
FunctionCombineHandle.php
File metadata and controls
55 lines (52 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace App\ApiJson\Handle;
class FunctionCombineHandle extends AbstractHandle
{
protected string $keyWord = '@combine';
public function buildModel()
{
if (!in_array($this->keyWord, array_keys($this->condition->getCondition()))) {
return;
}
foreach (array_filter($this->condition->getCondition(), function($key){
return $key == $this->keyWord;
}, ARRAY_FILTER_USE_KEY) as $key => $value)
{
$conditionKeyArr = explode(',', $value);
$op = [
'&' => [],
'|' => [],
'!' => []
];
foreach ($conditionKeyArr as $conditionKey) {
if (str_starts_with($conditionKey, '&')) {
$op['&'] = $conditionKey;
} else if (str_starts_with($conditionKey, '!')) {
$op['!'] = $conditionKey;
} else {
$op['|'] = $conditionKey;
}
}
$sql = [];
$bind = [];
$queryWhere = $this->condition->getQueryWhere();
foreach ($op as $opKey => $opValue) {
if (empty($value)) continue;
$subSql = [];
foreach ($opValue as $key) {
$subSql[] = $queryWhere[$key]['sql'];
$bind = array_merge($bind, $queryWhere[$key]['bind']);
unset($queryWhere[$key]);
}
$boolean = ' OR ';
if ($opKey == '&') $boolean = ' AND ';
$pref = ($opKey == '!') ? '!' : '';
$sql[] = sprintf('%s(%s)', $pref, join($boolean, $subSql));
}
$queryWhere[$this->keyWord] = [
'sql' => join(' AND ', $sql),
'bind' => $bind
];
}
}
}