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 | * Query constructor. |
||
47 | * |
||
48 | * @param array|string $endpoint Path of endpoint |
||
49 | * @param array $attributes List of attributes which should be set |
||
50 | * @throws QueryException |
||
51 | */ |
||
52 | 23 | public function __construct($endpoint, array $attributes = []) |
|
65 | |||
66 | const AVAILABLE_OPERATORS = [ |
||
67 | '-', // Does not have |
||
68 | '=', // Equal |
||
69 | '>', // More than |
||
70 | '<' // Less than |
||
71 | ]; |
||
72 | |||
73 | /** |
||
74 | * Where logic of query |
||
75 | * |
||
76 | * @param string $key |
||
77 | * @param bool $value |
||
78 | * @param string|null $operator |
||
79 | * @return \RouterOS\Query |
||
80 | * @throws \RouterOS\Exceptions\ClientException |
||
81 | * @since 1.0.0 |
||
82 | */ |
||
83 | public function where(string $key, $value = true, string $operator = ''): self |
||
98 | |||
99 | /** |
||
100 | * Append additional operations |
||
101 | * |
||
102 | * @param string $operations |
||
103 | * @return \RouterOS\Query |
||
104 | * @since 1.0.0 |
||
105 | */ |
||
106 | public function operations(string $operations): self |
||
111 | |||
112 | /** |
||
113 | * Append tag to query (it should be at end) |
||
114 | * |
||
115 | * @param string $name |
||
116 | * @return \RouterOS\Query |
||
117 | * @since 1.0.0 |
||
118 | */ |
||
119 | public function tag(string $name): self |
||
124 | |||
125 | /** |
||
126 | * Append to array yet another attribute of query |
||
127 | * |
||
128 | * @param string $word |
||
129 | * @return \RouterOS\Query |
||
130 | */ |
||
131 | 2 | public function add(string $word): Query |
|
136 | |||
137 | /** |
||
138 | * Get attributes array of current query |
||
139 | * |
||
140 | * @return array |
||
141 | */ |
||
142 | 15 | public function getAttributes(): array |
|
146 | |||
147 | /** |
||
148 | * Set array of attributes |
||
149 | * |
||
150 | * @param array $attributes |
||
151 | * @return \RouterOS\Query |
||
152 | * @since 0.7 |
||
153 | */ |
||
154 | 22 | public function setAttributes(array $attributes): Query |
|
159 | |||
160 | /** |
||
161 | * Get endpoint of current query |
||
162 | * |
||
163 | * @return string|null |
||
164 | */ |
||
165 | 3 | public function getEndpoint() |
|
169 | |||
170 | /** |
||
171 | * Set endpoint of query |
||
172 | * |
||
173 | * @param string|null $endpoint |
||
174 | * @return \RouterOS\Query |
||
175 | * @since 0.7 |
||
176 | */ |
||
177 | 22 | public function setEndpoint(string $endpoint = null): Query |
|
182 | |||
183 | /** |
||
184 | * Build body of query |
||
185 | * |
||
186 | * @return array |
||
187 | * @throws \RouterOS\Exceptions\QueryException |
||
188 | */ |
||
189 | 13 | public function getQuery(): array |
|
211 | } |
||
212 |