1 | <?php |
||
17 | class Query implements QueryInterface |
||
18 | { |
||
19 | /** |
||
20 | * Array of query attributes |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | private $_attributes = []; |
||
25 | |||
26 | /** |
||
27 | * Some additional operations |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | private $_operations; |
||
32 | |||
33 | /** |
||
34 | * Tag of query |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $_tag; |
||
39 | |||
40 | /** |
||
41 | * Endpoint of query |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | private $_endpoint; |
||
46 | |||
47 | /** |
||
48 | * List of available operators for "->where()" method |
||
49 | */ |
||
50 | public const AVAILABLE_OPERATORS = [ |
||
51 | '-', // Does not have |
||
52 | '=', // Equal |
||
53 | '>', // More than |
||
54 | '<' // Less than |
||
55 | ]; |
||
56 | |||
57 | /** |
||
58 | * Query constructor. |
||
59 | * |
||
60 | * @param array|string $endpoint Path of endpoint |
||
61 | * @param array $attributes List of attributes which should be set |
||
62 | * |
||
63 | * @throws \RouterOS\Exceptions\QueryException |
||
64 | */ |
||
65 | 19 | public function __construct($endpoint, array $attributes = []) |
|
78 | |||
79 | /** |
||
80 | * Where logic of query |
||
81 | * |
||
82 | * @param string $key Key which need to find |
||
83 | * @param bool|string|int $value Value which need to check (by default true) |
||
84 | * @param bool|string|int $operator It may be one from list [-,=,>,<] |
||
85 | * |
||
86 | * @return \RouterOS\Interfaces\QueryInterface |
||
87 | * @throws \RouterOS\Exceptions\QueryException |
||
88 | * @since 1.0.0 |
||
89 | */ |
||
90 | 1 | public function where(string $key, $operator = null, $value = null): QueryInterface |
|
94 | |||
95 | /** |
||
96 | * Setter for write/update queries |
||
97 | * |
||
98 | * @param string $key Key which need to find |
||
99 | * @param bool|string|int $value Value which need to check (by default true) |
||
100 | * |
||
101 | * @return \RouterOS\Interfaces\QueryInterface |
||
102 | * @throws \RouterOS\Exceptions\QueryException |
||
103 | * @since 1.1 |
||
104 | */ |
||
105 | public function equal(string $key, $value = null): QueryInterface |
||
109 | |||
110 | /** |
||
111 | * Write world to RouterOS (the work is mine) |
||
112 | * |
||
113 | * @param string $key Key which need to find |
||
114 | * @param bool|string|int $value Value which need to check (by default true) |
||
115 | * @param bool|string|int $operator It may be one from list [-,=,>,<] |
||
116 | * |
||
117 | * @return \RouterOS\Interfaces\QueryInterface |
||
118 | * @throws \RouterOS\Exceptions\QueryException |
||
119 | */ |
||
120 | 1 | private function world(string $key, $operator = null, $value = null): QueryInterface |
|
147 | |||
148 | /** |
||
149 | * Append additional operations |
||
150 | * |
||
151 | * @param string $operations |
||
152 | * |
||
153 | * @return \RouterOS\Interfaces\QueryInterface |
||
154 | * @since 1.0.0 |
||
155 | */ |
||
156 | 1 | public function operations(string $operations): QueryInterface |
|
161 | |||
162 | /** |
||
163 | * Append tag to query (it should be at end) |
||
164 | * |
||
165 | * @param string $name |
||
166 | * |
||
167 | * @return \RouterOS\Interfaces\QueryInterface |
||
168 | * @since 1.0.0 |
||
169 | */ |
||
170 | 1 | public function tag(string $name): QueryInterface |
|
175 | |||
176 | /** |
||
177 | * Append to array yet another attribute of query |
||
178 | * |
||
179 | * @param string $word |
||
180 | * |
||
181 | * @return \RouterOS\Interfaces\QueryInterface |
||
182 | */ |
||
183 | 1 | public function add(string $word): QueryInterface |
|
188 | |||
189 | /** |
||
190 | * Get attributes array of current query |
||
191 | * |
||
192 | * @return array |
||
193 | */ |
||
194 | 19 | public function getAttributes(): array |
|
198 | |||
199 | /** |
||
200 | * Set array of attributes |
||
201 | * |
||
202 | * @param array $attributes |
||
203 | * |
||
204 | * @return \RouterOS\Interfaces\QueryInterface |
||
205 | * @since 0.7 |
||
206 | */ |
||
207 | 19 | public function setAttributes(array $attributes): QueryInterface |
|
212 | |||
213 | /** |
||
214 | * Get endpoint of current query |
||
215 | * |
||
216 | * @return string|null |
||
217 | */ |
||
218 | public function getEndpoint(): ?string |
||
222 | |||
223 | /** |
||
224 | * Set endpoint of query |
||
225 | * |
||
226 | * @param string|null $endpoint |
||
227 | * |
||
228 | * @return \RouterOS\Interfaces\QueryInterface |
||
229 | * @since 0.7 |
||
230 | */ |
||
231 | 19 | public function setEndpoint(string $endpoint = null): QueryInterface |
|
236 | |||
237 | /** |
||
238 | * Build body of query |
||
239 | * |
||
240 | * @return array |
||
241 | * @throws \RouterOS\Exceptions\QueryException |
||
242 | */ |
||
243 | 19 | public function getQuery(): array |
|
265 | } |
||
266 |