|
39 | 39 |
|
40 | 40 | class Handle
|
41 | 41 | {
|
| 42 | + |
42 | 43 | /**
|
43 | 44 | * 替换规则
|
44 | 45 | * @var AbstractReplace[]
|
45 | 46 | */
|
46 | 47 | protected array $replaceRules = [
|
47 |
| - KeywordCountReplace::class, |
48 |
| - KeywordPageReplace::class, |
49 |
| - QuoteReplace::class, |
| 48 | + 'query' => [ |
| 49 | + KeywordCountReplace::class, |
| 50 | + KeywordPageReplace::class, |
| 51 | + QuoteReplace::class, |
| 52 | + ], |
| 53 | + 'update' => [] |
50 | 54 | ];
|
51 | 55 |
|
52 | 56 |
|
53 | 57 | /**
|
54 | 58 | * 匹配规则 根据从上自下优先先匹先出
|
55 | 59 | * @var AbstractHandle[]
|
56 | 60 | */
|
57 |
| - protected array $methodRules = [ |
58 |
| - FunctionProcedureHandle::class, |
59 |
| - FunctionColumnHandle::class, |
60 |
| - FunctionHavingHandle::class, |
61 |
| - FunctionOffsetHandle::class, |
62 |
| - FunctionLimitHandle::class, |
63 |
| - FunctionGroupHandle::class, |
64 |
| - FunctionOrderHandle::class, |
65 |
| - WhereJsonContainsHandle::class, |
66 |
| - WhereBetweenHandle::class, |
67 |
| - WhereExistsHandle::class, |
68 |
| - WhereRegexpHandle::class, |
69 |
| - WhereNotInHandle::class, |
70 |
| - WhereLikeHandle::class, |
71 |
| - WhereRawHandle::class, |
72 |
| - WhereInHandle::class, |
73 |
| - WhereSubQueryHandle::class, |
74 |
| - WhereOpHandle::class, |
75 |
| - WhereHandle::class, |
76 |
| - FunctionCombineHandle::class |
| 61 | + protected array $queryMethodRules = [ |
| 62 | + 'query' => [ |
| 63 | + FunctionProcedureHandle::class, |
| 64 | + FunctionColumnHandle::class, |
| 65 | + FunctionHavingHandle::class, |
| 66 | + FunctionOffsetHandle::class, |
| 67 | + FunctionLimitHandle::class, |
| 68 | + FunctionGroupHandle::class, |
| 69 | + FunctionOrderHandle::class, |
| 70 | + WhereJsonContainsHandle::class, |
| 71 | + WhereBetweenHandle::class, |
| 72 | + WhereExistsHandle::class, |
| 73 | + WhereRegexpHandle::class, |
| 74 | + WhereNotInHandle::class, |
| 75 | + WhereLikeHandle::class, |
| 76 | + WhereRawHandle::class, |
| 77 | + WhereInHandle::class, |
| 78 | + WhereSubQueryHandle::class, |
| 79 | + WhereOpHandle::class, |
| 80 | + WhereHandle::class, |
| 81 | + FunctionCombineHandle::class |
| 82 | + ], |
| 83 | + 'update' => [ |
| 84 | + |
| 85 | + ] |
77 | 86 | ];
|
78 | 87 |
|
79 | 88 | public function __construct(protected ConditionEntity $conditionEntity, protected TableEntity $tableEntity)
|
80 | 89 | {
|
81 | 90 | }
|
82 | 91 |
|
83 |
| - public function build() |
| 92 | + public function buildQuery() |
| 93 | + { |
| 94 | + $this->build('query'); |
| 95 | + } |
| 96 | + |
| 97 | + public function buildUpdate() |
| 98 | + { |
| 99 | + $this->build('update'); |
| 100 | + } |
| 101 | + |
| 102 | + protected function build(string $action) |
84 | 103 | {
|
85 |
| - foreach ($this->replaceRules as $replaceRuleClass) { |
| 104 | + foreach ($this->replaceRules[$action] ?? [] as $replaceRuleClass) { |
86 | 105 | /** @var AbstractReplace $replaceRule */
|
87 | 106 | $replaceRule = new $replaceRuleClass($this->conditionEntity);
|
88 | 107 | $replaceRule->handle();
|
89 | 108 | }
|
90 |
| - foreach ($this->methodRules as $methodRuleClass) { |
| 109 | + foreach ($this->queryMethodRules[$action] ?? [] as $methodRuleClass) { |
91 | 110 | /** @var AbstractHandle $methodRule */
|
92 | 111 | $methodRule = new $methodRuleClass($this->conditionEntity);
|
93 | 112 | $methodRule->handle();
|
|
0 commit comments