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 | 24 | ||
38 | /** |
||
39 | 24 | * Endpoint of query |
|
40 | 20 | * |
|
41 | 20 | * @var string |
|
42 | 4 | */ |
|
43 | 3 | private $_endpoint; |
|
44 | 3 | ||
45 | 3 | /** |
|
46 | * Query constructor. |
||
47 | 1 | * |
|
48 | * @param array|string $endpoint Path of endpoint |
||
49 | 23 | * @param array $attributes List of attributes which should be set |
|
50 | * @throws QueryException |
||
51 | */ |
||
52 | public function __construct($endpoint, array $attributes = []) |
||
65 | |||
66 | const AVAILABLE_OPERATORS = [ |
||
67 | '-', // Does not have |
||
68 | 16 | '=', // Equal |
|
69 | '>', // More than |
||
70 | 16 | '<' // 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 | 23 | * @throws \RouterOS\Exceptions\ClientException |
|
81 | * @since 1.0.0 |
||
82 | 23 | */ |
|
83 | 23 | public function where(string $key, $value = true, string $operator = ''): self |
|
98 | |||
99 | /** |
||
100 | * Append additional operations |
||
101 | * |
||
102 | * @param string $operations |
||
103 | 23 | * @return \RouterOS\Query |
|
104 | * @since 1.0.0 |
||
105 | 23 | */ |
|
106 | 23 | public function operations(string $operations): self |
|
111 | |||
112 | /** |
||
113 | * Append tag to query (it should be at end) |
||
114 | * |
||
115 | 14 | * @param string $name |
|
116 | * @return \RouterOS\Query |
||
117 | 14 | * @since 1.0.0 |
|
118 | 1 | */ |
|
119 | public function tag(string $name): self |
||
124 | |||
125 | 13 | /** |
|
126 | * Append to array yet another attribute of query |
||
127 | * |
||
128 | * @param string $word |
||
129 | * @return \RouterOS\Query |
||
130 | */ |
||
131 | public function add(string $word): Query |
||
136 | |||
137 | /** |
||
138 | * Get attributes array of current query |
||
139 | * |
||
140 | * @return array |
||
141 | */ |
||
142 | 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 | public function setAttributes(array $attributes): Query |
||
159 | |||
160 | /** |
||
161 | * Get endpoint of current query |
||
162 | * |
||
163 | * @return string|null |
||
164 | */ |
||
165 | 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 | 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 | public function getQuery(): array |
||
211 | } |
||
212 |