1 | <?php |
||
13 | class Query |
||
14 | { |
||
15 | protected $repo; |
||
16 | protected $predicate; |
||
17 | protected $limit = array(); |
||
18 | protected $orderBy = array(); |
||
19 | |||
20 | /** |
||
21 | * Constructor |
||
22 | * |
||
23 | * @param Repository $repository The repo this query will run against. |
||
24 | */ |
||
25 | 4 | public function __construct(Repository $repository) |
|
30 | |||
31 | /** |
||
32 | * Set a limit on the number of documents returned. An offset from 0 can |
||
33 | * also be specified. |
||
34 | * |
||
35 | * @param int $count The number of documents to return. |
||
36 | * @param int $offset The offset from which to return. |
||
37 | * |
||
38 | * @return Query The same instance of this class. |
||
39 | */ |
||
40 | 1 | public function limit($count, $offset = 0) |
|
46 | |||
47 | /** |
||
48 | * Sets the fields to order the results by. They should be in the |
||
49 | * the format 'fieldname ASC|DESC'. e.g 'dateAdded DESC'. |
||
50 | * |
||
51 | * @param mixed $fields An array comprising strings in the above format |
||
52 | * (or a single string) |
||
53 | * |
||
54 | * @return Query The same instance of this class. |
||
55 | */ |
||
56 | 1 | public function orderBy($fields) |
|
62 | |||
63 | /** |
||
64 | * @see Query::andWhere |
||
65 | * |
||
66 | * @return Query The same instance of this class. |
||
67 | */ |
||
68 | 1 | public function where($field, $operator = null, $value = null) |
|
72 | |||
73 | /** |
||
74 | * Adds a boolean AND predicate for this query, |
||
75 | * |
||
76 | * @param string|Closure $field The name of the field to match or an anonymous |
||
77 | * function that will define sub predicates. |
||
78 | * @param string $operator An operator from the allowed list. |
||
79 | * @param string $value The value to compare against. |
||
80 | * |
||
81 | * @return Query The same instance of this class. |
||
82 | */ |
||
83 | 1 | public function andWhere($field, $operator = null, $value = null) |
|
89 | |||
90 | /** |
||
91 | * Adds a boolean OR predicate for this query, |
||
92 | * |
||
93 | * @param string|Closure $field The name of the field to match or an anonymous |
||
94 | * function that will define sub predicates. |
||
95 | * @param string $operator An operator from the allowed list. |
||
96 | * @param string $value The value to compare against. |
||
97 | * |
||
98 | * @return Query The same instance of this class. |
||
99 | */ |
||
100 | public function orWhere($field, $operator = null, $value = null) |
||
106 | |||
107 | /** |
||
108 | * Runs the query. |
||
109 | * |
||
110 | * @return Result The documents returned from this query. |
||
111 | */ |
||
112 | public function execute() |
||
118 | } |
||
119 |