22
33namespace App \ApiJson \Entity ;
44
5- use App \ApiJson \Handle \FunctionLimitHandle ;
6- use App \ApiJson \Handle \FunctionOffsetHandle ;
7- use App \ApiJson \Interface \QueryInterface ;
8- use App \ApiJson \Handle \AbstractHandle ;
9- use App \ApiJson \Handle \FunctionColumnHandle ;
10- use App \ApiJson \Handle \FunctionGroupHandle ;
11- use App \ApiJson \Handle \FunctionHavingHandle ;
12- use App \ApiJson \Handle \FunctionOrderHandle ;
13- use App \ApiJson \Handle \WhereBetweenHandle ;
14- use App \ApiJson \Handle \WhereExistsHandle ;
15- use App \ApiJson \Handle \WhereHandle ;
16- use App \ApiJson \Handle \WhereInHandle ;
17- use App \ApiJson \Handle \WhereJsonContainsHandle ;
18- use App \ApiJson \Handle \WhereLikeHandle ;
19- use App \ApiJson \Handle \WhereRawHandle ;
20- use App \ApiJson \Handle \WhereRegexpHandle ;
21- use App \ApiJson \Method \AbstractMethod ;
22- use App \ApiJson \Replace \AbstractReplace ;
23- use App \ApiJson \Replace \KeywordCountReplace ;
24- use App \ApiJson \Replace \KeywordPageReplace ;
25- use App \ApiJson \Replace \QuoteReplace ;
26-
275class ConditionEntity
286{
29- /**
30- * 替换规则
31- * @var AbstractReplace[]
32- */
33- protected array $ replaceRules = [
34- KeywordCountReplace::class,
35- KeywordPageReplace::class,
36- QuoteReplace::class,
37- ];
38-
39-
40- /**
41- * 匹配规则 根据从上自下优先先匹先出
42- * @var AbstractHandle[]
43- */
44- protected array $ methodRules = [
45- FunctionColumnHandle::class,
46- FunctionHavingHandle::class,
47- FunctionOffsetHandle::class,
48- FunctionLimitHandle::class,
49- FunctionGroupHandle::class,
50- FunctionOrderHandle::class,
51- WhereJsonContainsHandle::class,
52- WhereBetweenHandle::class,
53- WhereExistsHandle::class,
54- WhereRegexpHandle::class,
55- WhereLikeHandle::class,
56- WhereRawHandle::class,
57- WhereInHandle::class,
58- WhereHandle::class,
59- ];
7+ protected array $ changeLog = [];
608
619 /**
6210 * @param array $condition 条件
@@ -65,29 +13,27 @@ public function __construct(protected array $condition, protected array $extendD
6513 {
6614 }
6715
68- protected function replaceHandle ( $ key , $ value , array $ condition = [] ): array
16+ public function getExtendData ( ): array
6917 {
70- foreach ($ this ->replaceRules as $ rule ) {
71- /** @var AbstractReplace $replaceRule */
72- $ replaceRule = new $ rule ($ key , $ value , $ condition , $ this ->extendData );
73- $ response = $ replaceRule ->handle ();
74- if (!is_null ($ response )) return $ response ;
75- }
76- return [$ key , $ value ];
18+ return $ this ->extendData ;
7719 }
7820
79- /**
80- * 整理语句
81- */
82- public function setQueryCondition (QueryInterface $ query )
21+ public function setCondition (array $ condition )
22+ {
23+ $ this ->log ($ condition );
24+ $ this ->condition = $ condition ;
25+ }
26+
27+ public function getCondition (): array
28+ {
29+ return $ this ->condition ;
30+ }
31+
32+ protected function log (array $ condition )
8333 {
84- foreach ($ this ->condition as $ key => $ value ) {
85- [$ key , $ value ] = $ this ->replaceHandle ($ key , $ value , $ this ->condition ); //解决引用问题
86- /** @var AbstractMethod $rule */
87- foreach ($ this ->methodRules as $ rule ) {
88- $ methodRule = new $ rule ($ query , $ key , $ value );
89- if ($ methodRule ->handle ()) break ;
90- }
91- }
34+ $ this ->changeLog [] = [
35+ 'old ' => $ this ->condition ,
36+ 'new ' => $ condition
37+ ];
9238 }
9339}
0 commit comments