@@ -8,11 +8,10 @@ class ShardingQuery
88{
99
1010 /**
11- * 数据库查询的回调
12- * 回调必须返回数组类型
13- * @var callable
11+ * 查询闭包
12+ * @var \Closure
1413 */
15- public $ callback ;
14+ public $ query ;
1615
1716 /**
1817 * 数据表列表
@@ -28,29 +27,17 @@ class ShardingQuery
2827 public $ field ;
2928
3029 /**
31- * join
30+ * innerJoin
3231 * @var array
3332 */
3433 public $ innerJoin ;
3534
3635 /**
37- * join
36+ * leftJoin
3837 * @var array
3938 */
4039 public $ leftJoin ;
4140
42- /**
43- * join
44- * @var array
45- */
46- public $ rightJoin ;
47-
48- /**
49- * join
50- * @var array
51- */
52- public $ fullJoin ;
53-
5441 /**
5542 * 条件
5643 * @var string
@@ -101,9 +88,9 @@ public function __construct(array $config)
10188 {
10289 foreach ($ config as $ key => $ value ) {
10390 switch ($ key ) {
104- case 'callback ' :
105- if (!is_callable ($ value )) {
106- throw new \RuntimeException ("'callback ' is not a callable type. " );
91+ case 'query ' :
92+ if (!($ value instanceof \Closure )) {
93+ throw new \RuntimeException ("'query ' is not a closure type. " );
10794 }
10895 $ this ->$ key = $ value ;
10996 break ;
@@ -131,18 +118,6 @@ public function __construct(array $config)
131118 }
132119 $ this ->$ key = $ value ;
133120 break ;
134- case 'rightJoin ' :
135- if (!is_array ($ value )) {
136- throw new \RuntimeException ("'rightJoin' is not a array type. " );
137- }
138- $ this ->$ key = $ value ;
139- break ;
140- case 'fullJoin ' :
141- if (!is_array ($ value )) {
142- throw new \RuntimeException ("'fullJoin' is not a array type. " );
143- }
144- $ this ->$ key = $ value ;
145- break ;
146121 case 'where ' :
147122 if (!is_string ($ value )) {
148123 throw new \RuntimeException ("'where' is not a string type. " );
@@ -187,7 +162,7 @@ public function select()
187162 $ tmpSql = str_replace (static ::$ tableSymbol , $ tableName , $ sql );
188163 $ tmpSql = "{$ tmpSql } LIMIT {$ item ['limit ' ]} OFFSET {$ item ['offset ' ]}" ;
189164 $ this ->log (['sql ' => $ tmpSql ]);
190- $ result = call_user_func ($ this ->callback , $ tmpSql );
165+ $ result = call_user_func ($ this ->query , $ tmpSql );
191166 $ this ->log (['resultCount ' => count ($ result )]);
192167 $ data = array_merge ($ data , $ result );
193168 }
@@ -210,8 +185,8 @@ protected function stats($table)
210185 }
211186 $ sql = str_replace (static ::$ tableSymbol , $ tableName , $ sql );
212187 $ this ->log (['sql ' => $ sql ]);
213- $ result = call_user_func ($ this ->callback , $ sql );
214- $ first = array_pop ($ result );
188+ $ result = call_user_func ($ this ->query , $ sql );
189+ $ first = ( array ) array_pop ($ result );
215190 $ count = array_pop ($ first );
216191 $ this ->log (['result ' => $ count ]);
217192 $ start = $ end ;
@@ -285,16 +260,6 @@ protected function sql()
285260 $ sql .= " LEFT JOIN {$ item }" ;
286261 }
287262 }
288- if (!empty ($ this ->rightJoin )) {
289- foreach ($ this ->rightJoin as $ item ) {
290- $ sql .= " RIGHT JOIN {$ item }" ;
291- }
292- }
293- if (!empty ($ this ->fullJoin )) {
294- foreach ($ this ->fullJoin as $ item ) {
295- $ sql .= " FULL JOIN {$ item }" ;
296- }
297- }
298263 if (!empty ($ this ->where )) {
299264 $ sql .= " WHERE {$ this ->where }" ;
300265 }
@@ -317,7 +282,7 @@ public function count()
317282 }
318283
319284 /**
320- * 记录日志
285+ * 记录追踪数据
321286 */
322287 protected function log ($ message )
323288 {
0 commit comments