1 | <?php |
||
20 | class QueryBuilder { |
||
21 | |||
22 | /** |
||
23 | * @var ExpressionValidator |
||
24 | */ |
||
25 | private $expressionValidator; |
||
26 | |||
27 | /** |
||
28 | * @var UsageValidator |
||
29 | */ |
||
30 | private $usageValidator; |
||
31 | |||
32 | /** |
||
33 | * @var QueryPrefixBuilder |
||
34 | */ |
||
35 | private $prefixBuilder; |
||
36 | |||
37 | /** |
||
38 | * @var string[] list of expressions to select |
||
39 | */ |
||
40 | private $selects = array(); |
||
41 | |||
42 | /** |
||
43 | * @var string uniqueness constraint, one of DISTINCT, REDUCED or empty |
||
44 | */ |
||
45 | private $uniqueness = ''; |
||
46 | |||
47 | /** |
||
48 | * @var string form of the query, one of SELECT or DESCRIBE |
||
49 | */ |
||
50 | private $queryForm = null; |
||
51 | |||
52 | /** |
||
53 | * @var GraphBuilder |
||
54 | */ |
||
55 | private $graphBuilder; |
||
56 | |||
57 | /** |
||
58 | * @var QueryModifierBuilder |
||
59 | */ |
||
60 | private $modifierBuilder; |
||
61 | |||
62 | /** |
||
63 | * @var string[] $prefixes |
||
64 | * @throws InvalidArgumentException |
||
65 | */ |
||
66 | public function __construct( array $prefixes = array() ) { |
||
73 | |||
74 | /** |
||
75 | * @since 0.3 |
||
76 | * |
||
77 | * @return string[] list of expressions to select |
||
78 | */ |
||
79 | public function getSelects() { |
||
82 | |||
83 | /** |
||
84 | * Specifies the expressions to select. |
||
85 | * |
||
86 | * @param string|string[] $expressions |
||
87 | * @return self |
||
88 | * @throws InvalidArgumentException |
||
89 | * @throws RuntimeException |
||
90 | */ |
||
91 | public function select( $expressions /* expressions ... */ ) { |
||
99 | |||
100 | /** |
||
101 | * Specifies the expressions to select. Duplicate results are eliminated. |
||
102 | * |
||
103 | * @since 0.3 |
||
104 | * |
||
105 | * @param string|string[] $expressions |
||
106 | * @return self |
||
107 | * @throws InvalidArgumentException |
||
108 | * @throws RuntimeException |
||
109 | */ |
||
110 | public function selectDistinct( $expressions /* expressions ... */ ) { |
||
119 | |||
120 | /** |
||
121 | * Specifies the expressions to select. Duplicate results may be eliminated. |
||
122 | * |
||
123 | * @since 0.3 |
||
124 | * |
||
125 | * @param string|string[] $expressions |
||
126 | * @return self |
||
127 | * @throws InvalidArgumentException |
||
128 | * @throws RuntimeException |
||
129 | */ |
||
130 | public function selectReduced( $expressions /* expressions ... */ ) { |
||
139 | |||
140 | /** |
||
141 | * Specifies the expressions to describe. |
||
142 | * |
||
143 | * @since 0.4 |
||
144 | * |
||
145 | * @param string|string[] $expressions |
||
146 | * @return self |
||
147 | * @throws InvalidArgumentException |
||
148 | * @throws RuntimeException |
||
149 | */ |
||
150 | public function describe( $expressions /* expressions ... */ ) { |
||
162 | |||
163 | private function setQueryForm( $queryForm ) { |
||
170 | |||
171 | private function addExpressions( array $expressions, $options = null ) { |
||
189 | |||
190 | /** |
||
191 | * Adds the given triple as a condition. |
||
192 | * |
||
193 | * @param string $subject |
||
194 | * @param string $predicate |
||
195 | * @param string $object |
||
196 | * @return self |
||
197 | * @throws InvalidArgumentException |
||
198 | */ |
||
199 | public function where( $subject, $predicate, $object ) { |
||
203 | |||
204 | /** |
||
205 | * Adds the given triple/double/single value as an additional condition |
||
206 | * to the previously added condition. |
||
207 | * |
||
208 | * @param string $subject |
||
209 | * @param string|null $predicate |
||
210 | * @param string|null $object |
||
211 | * @return self |
||
212 | * @throws InvalidArgumentException |
||
213 | */ |
||
214 | public function also( $subject, $predicate = null, $object = null ) { |
||
218 | |||
219 | /** |
||
220 | * Adds the given graph or triple as an optional condition. |
||
221 | * |
||
222 | * @since 0.3 |
||
223 | * |
||
224 | * @param string|GraphBuilder $subject |
||
225 | * @param string|null $predicate |
||
226 | * @param string|null $object |
||
227 | * @return self |
||
228 | * @throws InvalidArgumentException |
||
229 | */ |
||
230 | public function optional( $subject, $predicate = null, $object = null ) { |
||
234 | |||
235 | /** |
||
236 | * Adds the given expression as a filter to this query. |
||
237 | * |
||
238 | * @since 0.3 |
||
239 | * |
||
240 | * @param string $expression |
||
241 | * @return self |
||
242 | * @throws InvalidArgumentException |
||
243 | */ |
||
244 | public function filter( $expression ) { |
||
248 | |||
249 | /** |
||
250 | * Adds a filter that the given graph or triple exists. |
||
251 | * |
||
252 | * @since 0.3 |
||
253 | * |
||
254 | * @param string|GraphBuilder $subject |
||
255 | * @param string|null $predicate |
||
256 | * @param string|null $object |
||
257 | * @return self |
||
258 | * @throws InvalidArgumentException |
||
259 | */ |
||
260 | public function filterExists( $subject, $predicate = null, $object = null ) { |
||
264 | |||
265 | /** |
||
266 | * Adds a filter that the given graph or triple does not exist. |
||
267 | * |
||
268 | * @since 0.3 |
||
269 | * |
||
270 | * @param string|GraphBuilder $subject |
||
271 | * @param string|null $predicate |
||
272 | * @param string|null $object |
||
273 | * @return self |
||
274 | * @throws InvalidArgumentException |
||
275 | */ |
||
276 | public function filterNotExists( $subject, $predicate = null, $object = null ) { |
||
280 | |||
281 | /** |
||
282 | * Adds the given graphs as alternative conditions. |
||
283 | * |
||
284 | * @since 0.3 |
||
285 | * |
||
286 | * @param GraphBuilder|GraphBuilder[] $graphs |
||
287 | * @return self |
||
288 | * @throws InvalidArgumentException |
||
289 | */ |
||
290 | public function union( $graphs /* graphs ... */ ) { |
||
294 | |||
295 | /** |
||
296 | * Adds the given subquery. |
||
297 | * |
||
298 | * @param QueryBuilder $query |
||
299 | * @return self |
||
300 | * @throws InvalidArgumentException |
||
301 | */ |
||
302 | public function subquery( QueryBuilder $query ) { |
||
306 | |||
307 | /** |
||
308 | * Creates a new subquery builder. |
||
309 | * |
||
310 | * @return QueryBuilder |
||
311 | */ |
||
312 | public function newSubquery() { |
||
315 | |||
316 | /** |
||
317 | * Creates a new subgraph builder. |
||
318 | * |
||
319 | * @since 0.3 |
||
320 | * |
||
321 | * @return GraphBuilder |
||
322 | */ |
||
323 | public function newSubgraph() { |
||
326 | |||
327 | /** |
||
328 | * Sets the GROUP BY modifier. |
||
329 | * |
||
330 | * @param string|string[] $expressions |
||
331 | * @return self |
||
332 | * @throws InvalidArgumentException |
||
333 | */ |
||
334 | public function groupBy( $expressions /* expressions ... */ ) { |
||
340 | |||
341 | /** |
||
342 | * Sets the HAVING modifier. |
||
343 | * |
||
344 | * @param string $expression |
||
345 | * @return self |
||
346 | * @throws InvalidArgumentException |
||
347 | */ |
||
348 | public function having( $expression ) { |
||
352 | |||
353 | /** |
||
354 | * Sets the ORDER BY modifier. |
||
355 | * |
||
356 | * @param string $expression |
||
357 | * @param string $direction one of ASC or DESC |
||
358 | * @return self |
||
359 | * @throws InvalidArgumentException |
||
360 | */ |
||
361 | public function orderBy( $expression, $direction = 'ASC' ) { |
||
365 | |||
366 | /** |
||
367 | * Sets the LIMIT modifier. |
||
368 | * |
||
369 | * @param int $limit |
||
370 | * @return self |
||
371 | * @throws InvalidArgumentException |
||
372 | */ |
||
373 | public function limit( $limit ) { |
||
377 | |||
378 | /** |
||
379 | * Sets the OFFSET modifier. |
||
380 | * |
||
381 | * @param int $offset |
||
382 | * @return self |
||
383 | * @throws InvalidArgumentException |
||
384 | */ |
||
385 | public function offset( $offset ) { |
||
389 | |||
390 | /** |
||
391 | * Returns the plain SPARQL string of this query. |
||
392 | * |
||
393 | * @param bool $includePrefixes |
||
394 | * @return string |
||
395 | * @throws InvalidArgumentException |
||
396 | * @throws RangeException |
||
397 | */ |
||
398 | public function getSPARQL( $includePrefixes = true ) { |
||
414 | |||
415 | private function formatSelects() { |
||
418 | |||
419 | /** |
||
420 | * @see self::getSPARQL |
||
421 | * |
||
422 | * @return string |
||
423 | */ |
||
424 | public function __toString() { |
||
427 | |||
428 | /** |
||
429 | * Returns the formatted SPARQL string of this query. |
||
430 | * |
||
431 | * @see QueryFormatter::format |
||
432 | * |
||
433 | * @return string |
||
434 | */ |
||
435 | public function format() { |
||
439 | |||
440 | } |
||
441 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.