1 | <?php |
||
15 | class Query implements QueryInterface |
||
16 | { |
||
17 | /** |
||
18 | * Array of query attributes |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | private $_attributes = []; |
||
23 | |||
24 | /** |
||
25 | * Some additional operations |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | private $_operations; |
||
30 | |||
31 | /** |
||
32 | * Tag of query |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | private $_tag; |
||
37 | |||
38 | /** |
||
39 | * Endpoint of query |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | private $_endpoint; |
||
44 | |||
45 | /** |
||
46 | * List of available operators for "->where()" method |
||
47 | */ |
||
48 | public const AVAILABLE_OPERATORS = [ |
||
49 | '-', // Does not have |
||
50 | '=', // Equal |
||
51 | '>', // More than |
||
52 | '<' // Less than |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * Query constructor. |
||
57 | * |
||
58 | * @param array|string $endpoint Path of endpoint |
||
59 | * @param array $attributes List of attributes which should be set |
||
60 | * @throws \RouterOS\Exceptions\QueryException |
||
61 | */ |
||
62 | 31 | public function __construct($endpoint, array $attributes = []) |
|
75 | |||
76 | /** |
||
77 | * Where logic of query |
||
78 | * |
||
79 | * @param string $key Key which need to find |
||
80 | * @param bool|string|int $value Value which need to check (by default true) |
||
81 | * @param bool|string|int $operator It may be one from list [-,=,>,<] |
||
82 | * @return \RouterOS\Query |
||
83 | * @throws \RouterOS\Exceptions\QueryException |
||
84 | * @since 1.0.0 |
||
85 | */ |
||
86 | 5 | public function where(string $key, $operator = null, $value = null): self |
|
113 | |||
114 | /** |
||
115 | * Append additional operations |
||
116 | * |
||
117 | * @param string $operations |
||
118 | * @return \RouterOS\Query |
||
119 | * @since 1.0.0 |
||
120 | */ |
||
121 | 2 | public function operations(string $operations): self |
|
126 | |||
127 | /** |
||
128 | * Append tag to query (it should be at end) |
||
129 | * |
||
130 | * @param string $name |
||
131 | * @return \RouterOS\Query |
||
132 | * @since 1.0.0 |
||
133 | */ |
||
134 | 2 | public function tag(string $name): self |
|
139 | |||
140 | /** |
||
141 | * Append to array yet another attribute of query |
||
142 | * |
||
143 | * @param string $word |
||
144 | * @return \RouterOS\Query |
||
145 | */ |
||
146 | 6 | public function add(string $word): Query |
|
151 | |||
152 | /** |
||
153 | * Get attributes array of current query |
||
154 | * |
||
155 | * @return array |
||
156 | */ |
||
157 | 22 | public function getAttributes(): array |
|
161 | |||
162 | /** |
||
163 | * Set array of attributes |
||
164 | * |
||
165 | * @param array $attributes |
||
166 | * @return \RouterOS\Query |
||
167 | * @since 0.7 |
||
168 | */ |
||
169 | 30 | public function setAttributes(array $attributes): Query |
|
174 | |||
175 | /** |
||
176 | * Get endpoint of current query |
||
177 | * |
||
178 | * @return string|null |
||
179 | */ |
||
180 | 3 | public function getEndpoint() |
|
184 | |||
185 | /** |
||
186 | * Set endpoint of query |
||
187 | * |
||
188 | * @param string|null $endpoint |
||
189 | * @return \RouterOS\Query |
||
190 | * @since 0.7 |
||
191 | */ |
||
192 | 30 | public function setEndpoint(string $endpoint = null): Query |
|
197 | |||
198 | /** |
||
199 | * Build body of query |
||
200 | * |
||
201 | * @return array |
||
202 | * @throws \RouterOS\Exceptions\QueryException |
||
203 | */ |
||
204 | 19 | public function getQuery(): array |
|
226 | } |
||
227 |