1 | <?php |
||
10 | class Condition |
||
11 | { |
||
12 | const LT = '<'; |
||
13 | const GT = '>'; |
||
14 | const EQ = '='; |
||
15 | const LE = '<='; |
||
16 | const GE = '>='; |
||
17 | |||
18 | protected static $comparatorInverseMap = [ |
||
19 | // inverse map for non-primary key condition |
||
20 | [ |
||
21 | self::LT => self::GT, |
||
22 | self::EQ => self::EQ, |
||
23 | self::GT => self::LT, |
||
24 | ], |
||
25 | // inverse map for primary key condition |
||
26 | [ |
||
27 | self::LT => self::GE, |
||
28 | self::GT => self::LE, |
||
29 | self::LE => self::GT, |
||
30 | self::GE => self::LT, |
||
31 | ], |
||
32 | ]; |
||
33 | |||
34 | protected static $comparatorOrderDirectionMap = [ |
||
35 | Order::ASCENDING => [ |
||
36 | Direction::FORWARD => self::GT, |
||
37 | Direction::BACKWARD => self::LT, |
||
38 | ], |
||
39 | Order::DESCENDING => [ |
||
40 | Direction::FORWARD => self::LT, |
||
41 | Direction::BACKWARD => self::GT, |
||
42 | ], |
||
43 | ]; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $left; |
||
49 | |||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $comparator; |
||
54 | |||
55 | /** |
||
56 | * @var int|string |
||
57 | */ |
||
58 | protected $right; |
||
59 | |||
60 | /** |
||
61 | * @var bool |
||
62 | */ |
||
63 | protected $isPrimaryKey; |
||
64 | |||
65 | /** |
||
66 | * @param Order $order |
||
67 | * @param int|string $value |
||
68 | * @param Direction $direction |
||
69 | * @param bool $exclusive |
||
70 | * @param bool $isPrimaryKey |
||
71 | * @param bool $isLastKey |
||
72 | * @param bool $isSupportQuery |
||
73 | * @return Condition |
||
74 | */ |
||
75 | 10 | public static function create(Order $order, $value, Direction $direction, $exclusive, $isPrimaryKey, $isLastKey, $isSupportQuery = false) |
|
91 | |||
92 | /** |
||
93 | * @param Order $order |
||
94 | * @param Direction $direction |
||
95 | * @param bool $exclusive |
||
96 | * @param bool $isPrimaryKey |
||
97 | * @param bool $isLastKey |
||
98 | * @param bool $isSupportQuery |
||
99 | * @return string |
||
100 | */ |
||
101 | 10 | protected static function compileComparator(Order $order, Direction $direction, $exclusive, $isPrimaryKey, $isLastKey, $isSupportQuery) |
|
117 | |||
118 | /** |
||
119 | * Condition constructor. |
||
120 | * |
||
121 | * @param string $left |
||
122 | * @param string $comparator |
||
123 | * @param int|string $right |
||
124 | * @param bool $isPrimaryKey |
||
125 | */ |
||
126 | 10 | public function __construct($left, $comparator, $right, $isPrimaryKey = false) |
|
133 | |||
134 | /** |
||
135 | * @param string $comparator |
||
136 | * @param bool $isPrimaryKey |
||
137 | * @return string |
||
138 | */ |
||
139 | 10 | protected static function validate($comparator, $isPrimaryKey) |
|
150 | |||
151 | /** |
||
152 | * @return array |
||
153 | */ |
||
154 | public function toArray() |
||
158 | |||
159 | /** |
||
160 | * @return string |
||
161 | */ |
||
162 | 10 | public function left() |
|
166 | |||
167 | /** |
||
168 | * @return string |
||
169 | */ |
||
170 | 10 | public function comparator() |
|
174 | |||
175 | /** |
||
176 | * @return int|string |
||
177 | */ |
||
178 | 10 | public function right() |
|
182 | |||
183 | /** |
||
184 | * @return bool |
||
185 | */ |
||
186 | public function isPrimaryKey() |
||
190 | |||
191 | /** |
||
192 | * @return static |
||
193 | */ |
||
194 | 10 | public function inverse() |
|
203 | } |
||
204 |