1 | <?php |
||
25 | class AliasDecorator |
||
26 | { |
||
27 | /** |
||
28 | * Target function postfix. All requests will be routed using this pattern and "or", "and" |
||
29 | * prefixes. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $target = 'where'; |
||
34 | |||
35 | /** |
||
36 | * Decorator will replace {@} with this alias in every where column. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $alias = ''; |
||
41 | |||
42 | /** |
||
43 | * Decorated query builder. |
||
44 | * |
||
45 | * @var AbstractSelect|RecordSelector |
||
46 | */ |
||
47 | protected $query = null; |
||
48 | |||
49 | /** |
||
50 | * @param AbstractSelect|RecordSelector $query |
||
51 | * @param string $target |
||
52 | * @param string $alias |
||
53 | */ |
||
54 | public function __construct($query, string $target = 'where', string $alias = '') |
||
60 | |||
61 | /** |
||
62 | * Update target method all where requests should be router into. |
||
63 | * |
||
64 | * @param string $target |
||
65 | */ |
||
66 | public function setTarget(string $target) |
||
70 | |||
71 | /** |
||
72 | * Get active routing target. |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | public function getTarget(): string |
||
80 | |||
81 | /** |
||
82 | * Simple WHERE condition with various set of arguments. Routed to where/on/having based |
||
83 | * on decorator settings. |
||
84 | * |
||
85 | * @see AbstractWhere |
||
86 | * |
||
87 | * @param mixed ...$args [(column, value), (column, operator, value)] |
||
88 | * |
||
89 | * @return $this|self |
||
90 | * |
||
91 | * @throws BuilderException |
||
92 | */ |
||
93 | public function where(...$args): AliasDecorator |
||
109 | |||
110 | /** |
||
111 | * @param array $orderBy In a form [expression => direction] |
||
112 | * |
||
113 | * @return \Spiral\ORM\Helpers\AliasDecorator |
||
114 | */ |
||
115 | public function orderBy(array $orderBy): AliasDecorator |
||
121 | |||
122 | /** |
||
123 | * Simple AND WHERE condition with various set of arguments. Routed to where/on/having based |
||
124 | * on decorator settings. |
||
125 | * |
||
126 | * @see AbstractWhere |
||
127 | * |
||
128 | * @param mixed ...$args [(column, value), (column, operator, value)] |
||
129 | * |
||
130 | * @return $this|self |
||
131 | * |
||
132 | * @throws BuilderException |
||
133 | */ |
||
134 | public function andWhere(...$args): AliasDecorator |
||
150 | |||
151 | /** |
||
152 | * Simple OR WHERE condition with various set of arguments. Routed to where/on/having based |
||
153 | * on decorator settings. |
||
154 | * |
||
155 | * @see AbstractWhere |
||
156 | * |
||
157 | * @param mixed ...$args [(column, value), (column, operator, value)] |
||
158 | * |
||
159 | * @return $this|self |
||
160 | * |
||
161 | * @throws BuilderException |
||
162 | */ |
||
163 | public function orWhere(...$args): AliasDecorator |
||
179 | |||
180 | /** |
||
181 | * Helper function used to replace {@} alias with actual table name. |
||
182 | * |
||
183 | * @param mixed $where |
||
184 | * |
||
185 | * @return mixed |
||
186 | */ |
||
187 | protected function prepare($where) |
||
208 | } |
||
209 |