22
33namespace App \ApiJson \Entity ;
44
5+ use App \ApiJson \Interface \QueryInterface ;
6+ use App \ApiJson \Handle \AbstractMethodHandle ;
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+
520class ConditionEntity
621{
22+ /**
23+ * 匹配规则 根据从上自下优先先匹先出
24+ * @var AbstractMethodHandle[]
25+ */
726 protected array $ methodRules = [
8-
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,
939 ];
1040
1141 /**
1242 * @param array $condition 条件
1343 */
1444 public function __construct (protected array $ condition )
1545 {
16- $ this ->formatSql ();
1746 }
1847
1948 /**
2049 * 整理语句
2150 */
22- protected function formatSql ( )
51+ public function setQueryCondition ( QueryInterface $ query )
2352 {
24-
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+ }
2559 }
2660}
0 commit comments