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