1+ <?php
2+
3+ namespace App \ApiJson \Entity ;
4+
5+ use App \ApiJson \Interface \QueryInterface ;
6+ use App \ApiJson \Handle \AbstractHandle ;
7+ use App \ApiJson \Handle \FunctionColumnHandle ;
8+ use App \ApiJson \Handle \FunctionGroupHandle ;
9+ use App \ApiJson \Handle \FunctionHavingHandle ;
10+ use App \ApiJson \Handle \FunctionOrderHandle ;
11+ use App \ApiJson \Handle \WhereBetweenHandle ;
12+ use App \ApiJson \Handle \WhereExistsHandle ;
13+ use App \ApiJson \Handle \WhereHandle ;
14+ use App \ApiJson \Handle \WhereInHandle ;
15+ use App \ApiJson \Handle \WhereJsonContainsHandle ;
16+ use App \ApiJson \Handle \WhereLikeHandle ;
17+ use App \ApiJson \Handle \WhereRawHandle ;
18+ use App \ApiJson \Handle \WhereRegexpHandle ;
19+
20+ class ConditionEntity
21+ {
22+ /**
23+ * 匹配规则 根据从上自下优先先匹先出
24+ * @var AbstractHandle[]
25+ */
26+ protected array $ methodRules = [
27+ FunctionColumnHandle::class,
28+ FunctionHavingHandle::class,
29+ FunctionGroupHandle::class,
30+ FunctionOrderHandle::class,
31+ WhereJsonContainsHandle::class,
32+ WhereBetweenHandle::class,
33+ WhereExistsHandle::class,
34+ WhereRegexpHandle::class,
35+ WhereLikeHandle::class,
36+ WhereRawHandle::class,
37+ WhereInHandle::class,
38+ WhereHandle::class,
39+ ];
40+
41+ /**
42+ * @param array $condition 条件
43+ */
44+ public function __construct (protected array $ condition )
45+ {
46+ }
47+
48+ /**
49+ * 整理语句
50+ */
51+ public function setQueryCondition (QueryInterface $ query )
52+ {
53+ foreach ($ this ->condition as $ key => $ value ) {
54+ foreach ($ this ->methodRules as $ rule ) {
55+ $ methodRule = new $ rule ($ query , $ key , $ value );
56+ if ($ methodRule ->handle ()) break ;
57+ }
58+ }
59+ }
60+ }
0 commit comments