3
3
namespace zyimm \query \build \resolves ;
4
4
5
5
6
+ use Closure ;
6
7
use Illuminate \Support \Str ;
7
8
8
9
/**
@@ -20,6 +21,8 @@ class QueryBuilder
20
21
21
22
public $ aliasCount = [];
22
23
24
+ private $ call = [];
25
+
23
26
private $ alias , $ field , $ operator ;
24
27
25
28
/**
@@ -93,13 +96,22 @@ public function build(): array
93
96
continue ;
94
97
}
95
98
// iteration fields
96
- foreach ($ fields as $ field ) {
97
- if (!isset ($ this ->params [$ field ])) {
98
- continue ;
99
- }
99
+ foreach ($ fields as $ key => $ field ) {
100
100
$ this ->operator = strtolower ($ operator );
101
- // defineAliasField
102
- $ this ->defineAliasField ($ field )->handle ();
101
+ if (is_string ($ field )) {
102
+ if (!isset ($ this ->params [$ field ]) || is_null ($ this ->params [$ field ])) {
103
+ continue ;
104
+ }
105
+ // defineAliasField
106
+ $ this ->defineAliasField ($ field );
107
+ }
108
+ if ($ field instanceof Closure) {
109
+ $ this ->call = [
110
+ 'call ' => $ field ,
111
+ 'field ' => $ key
112
+ ];
113
+ }
114
+ $ this ->handle ();
103
115
}
104
116
}
105
117
return $ this ->where ;
@@ -109,19 +121,18 @@ public function build(): array
109
121
* defineAliasField
110
122
*
111
123
* @param string $field
112
- * @return $this
124
+ * @return void
113
125
*/
114
- private function defineAliasField (string $ field = '' ): QueryBuilder
126
+ private function defineAliasField (string $ field = '' ): void
115
127
{
116
128
if (stripos ($ field , '. ' )) {
117
129
list ($ this ->alias , $ this ->field ) = explode ('. ' , $ field );
118
- $ this ->alias .= '. ' ;
119
- array_push ( $ this ->aliasCount , $ this ->alias ) ;
130
+ $ this ->alias .= '. ' ;
131
+ $ this ->aliasCount [] = $ this ->alias ;
120
132
} else {
121
133
$ this ->alias = '' ;
122
134
}
123
135
$ this ->field = $ field ;
124
- return $ this ;
125
136
}
126
137
127
138
/**
@@ -141,6 +152,24 @@ public function inBetween(): QueryBuilder
141
152
return $ this ;
142
153
}
143
154
155
+ /**
156
+ * execClosure
157
+ *
158
+ * @return $this
159
+ */
160
+ public function execClosure (): QueryBuilder
161
+ {
162
+ $ field = $ this ->call ['field ' ];
163
+ if ($ this ->call ['call ' ] instanceof Closure) {
164
+ $ this ->where [$ field .$ this ->operator ] = [
165
+ $ field ,
166
+ 'where ' ,
167
+ $ this ->call ['call ' ]
168
+ ];
169
+ }
170
+ return $ this ;
171
+ }
172
+
144
173
/**
145
174
* general
146
175
*
0 commit comments