1 | <?php |
||
28 | class Builder |
||
29 | { |
||
30 | /** |
||
31 | * The DocumentManager instance for this query |
||
32 | * |
||
33 | * @var DocumentManager |
||
34 | */ |
||
35 | private $dm; |
||
36 | |||
37 | /** |
||
38 | * The ClassMetadata instance. |
||
39 | * |
||
40 | * @var ClassMetadata |
||
41 | */ |
||
42 | private $class; |
||
43 | |||
44 | /** @var string */ |
||
45 | private $hydrationClass; |
||
46 | |||
47 | /** |
||
48 | * The Collection instance. |
||
49 | * |
||
50 | * @var Collection |
||
51 | */ |
||
52 | private $collection; |
||
53 | |||
54 | /** @var Stage[] */ |
||
55 | private $stages = []; |
||
56 | |||
57 | /** |
||
58 | * Create a new aggregation builder. |
||
59 | */ |
||
60 | 254 | public function __construct(DocumentManager $dm, string $documentName) |
|
66 | |||
67 | /** |
||
68 | * Adds new fields to documents. $addFields outputs documents that contain all |
||
69 | * existing fields from the input documents and newly added fields. |
||
70 | * |
||
71 | * The $addFields stage is equivalent to a $project stage that explicitly specifies |
||
72 | * all existing fields in the input documents and adds the new fields. |
||
73 | * |
||
74 | * If the name of the new field is the same as an existing field name (including _id), |
||
75 | * $addFields overwrites the existing value of that field with the value of the |
||
76 | * specified expression. |
||
77 | * |
||
78 | * @see http://docs.mongodb.com/manual/reference/operator/aggregation/addFields/ |
||
79 | */ |
||
80 | 1 | public function addFields() : Stage\AddFields |
|
86 | |||
87 | /** |
||
88 | * Categorizes incoming documents into groups, called buckets, based on a |
||
89 | * specified expression and bucket boundaries. |
||
90 | * |
||
91 | * Each bucket is represented as a document in the output. The document for |
||
92 | * each bucket contains an _id field, whose value specifies the inclusive |
||
93 | * lower bound of the bucket and a count field that contains the number of |
||
94 | * documents in the bucket. The count field is included by default when the |
||
95 | * output is not specified. |
||
96 | * |
||
97 | * @see https://docs.mongodb.com/manual/reference/operator/aggregation/bucket/ |
||
98 | */ |
||
99 | 2 | public function bucket() : Stage\Bucket |
|
105 | |||
106 | /** |
||
107 | * Categorizes incoming documents into a specific number of groups, called |
||
108 | * buckets, based on a specified expression. |
||
109 | * |
||
110 | * Bucket boundaries are automatically determined in an attempt to evenly |
||
111 | * distribute the documents into the specified number of buckets. Each |
||
112 | * bucket is represented as a document in the output. The document for each |
||
113 | * bucket contains an _id field, whose value specifies the inclusive lower |
||
114 | * bound and the exclusive upper bound for the bucket, and a count field |
||
115 | * that contains the number of documents in the bucket. The count field is |
||
116 | * included by default when the output is not specified. |
||
117 | * |
||
118 | * @see https://docs.mongodb.com/manual/reference/operator/aggregation/bucketAuto/ |
||
119 | */ |
||
120 | 2 | public function bucketAuto() : Stage\BucketAuto |
|
126 | |||
127 | /** |
||
128 | * Returns statistics regarding a collection or view. |
||
129 | * |
||
130 | * $collStats must be the first stage in an aggregation pipeline, or else |
||
131 | * the pipeline returns an error. |
||
132 | * |
||
133 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/collStats/ |
||
134 | */ |
||
135 | 1 | public function collStats() : Stage\CollStats |
|
141 | |||
142 | /** |
||
143 | * Returns a document that contains a count of the number of documents input |
||
144 | * to the stage. |
||
145 | * |
||
146 | * @see https://docs.mongodb.com/manual/reference/operator/aggregation/count/ |
||
147 | */ |
||
148 | 1 | public function count(string $fieldName) : Stage\Count |
|
154 | |||
155 | /** |
||
156 | * Executes the aggregation pipeline |
||
157 | */ |
||
158 | 17 | public function execute(array $options = []) : Iterator |
|
167 | |||
168 | 147 | public function expr() : Expr |
|
172 | |||
173 | /** |
||
174 | * Processes multiple aggregation pipelines within a single stage on the |
||
175 | * same set of input documents. |
||
176 | * |
||
177 | * Each sub-pipeline has its own field in the output document where its |
||
178 | * results are stored as an array of documents. |
||
179 | */ |
||
180 | 1 | public function facet() : Stage\Facet |
|
186 | |||
187 | /** |
||
188 | * Outputs documents in order of nearest to farthest from a specified point. |
||
189 | * |
||
190 | * A GeoJSON point may be provided as the first and only argument for |
||
191 | * 2dsphere queries. This single parameter may be a GeoJSON point object or |
||
192 | * an array corresponding to the point's JSON representation. If GeoJSON is |
||
193 | * used, the "spherical" option will default to true. |
||
194 | * |
||
195 | * You can only use this as the first stage of a pipeline. |
||
196 | * |
||
197 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/geoNear/ |
||
198 | * |
||
199 | * @param float|array|Point $x |
||
200 | * @param float $y |
||
201 | */ |
||
202 | 4 | public function geoNear($x, $y = null) : Stage\GeoNear |
|
208 | |||
209 | /** |
||
210 | * Returns the assembled aggregation pipeline |
||
211 | * |
||
212 | * For pipelines where the first stage is a $geoNear stage, it will apply |
||
213 | * the document filters and discriminator queries to the query portion of |
||
214 | * the geoNear operation. For all other pipelines, it prepends a $match stage |
||
215 | * containing the required query. |
||
216 | */ |
||
217 | 55 | public function getPipeline() : array |
|
237 | |||
238 | /** |
||
239 | * Returns a certain stage from the pipeline |
||
240 | */ |
||
241 | 55 | public function getStage(int $index) : Stage |
|
249 | |||
250 | /** |
||
251 | * Performs a recursive search on a collection, with options for restricting |
||
252 | * the search by recursion depth and query filter. |
||
253 | * |
||
254 | * @see https://docs.mongodb.org/manual/reference/operator/aggregation/graphLookup/ |
||
255 | * |
||
256 | * @param string $from Target collection for the $graphLookup operation to |
||
257 | * search, recursively matching the connectFromField to the connectToField. |
||
258 | */ |
||
259 | 10 | public function graphLookup(string $from) : Stage\GraphLookup |
|
265 | |||
266 | /** |
||
267 | * Groups documents by some specified expression and outputs to the next |
||
268 | * stage a document for each distinct grouping. |
||
269 | * |
||
270 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/group/ |
||
271 | */ |
||
272 | 4 | public function group() : Stage\Group |
|
278 | |||
279 | /** |
||
280 | * Set which class to use when hydrating results as document class instances. |
||
281 | */ |
||
282 | 4 | public function hydrate(string $className) : self |
|
288 | |||
289 | /** |
||
290 | * Returns statistics regarding the use of each index for the collection. |
||
291 | * |
||
292 | * @see https://docs.mongodb.org/manual/reference/operator/aggregation/indexStats/ |
||
293 | */ |
||
294 | 1 | public function indexStats() : Stage\IndexStats |
|
300 | |||
301 | /** |
||
302 | * Limits the number of documents passed to the next stage in the pipeline. |
||
303 | * |
||
304 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/limit/ |
||
305 | */ |
||
306 | 2 | public function limit(int $limit) : Stage\Limit |
|
312 | |||
313 | /** |
||
314 | * Performs a left outer join to an unsharded collection in the same |
||
315 | * database to filter in documents from the “joined” collection for |
||
316 | * processing. |
||
317 | * |
||
318 | * @see https://docs.mongodb.org/manual/reference/operator/aggregation/lookup/ |
||
319 | */ |
||
320 | 14 | public function lookup(string $from) : Stage\Lookup |
|
326 | |||
327 | /** |
||
328 | * Filters the documents to pass only the documents that match the specified |
||
329 | * condition(s) to the next pipeline stage. |
||
330 | * |
||
331 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/match/ |
||
332 | */ |
||
333 | 8 | public function match() : Stage\Match |
|
339 | |||
340 | /** |
||
341 | * Returns a query expression to be used in match stages |
||
342 | */ |
||
343 | 60 | public function matchExpr() : QueryExpr |
|
350 | |||
351 | /** |
||
352 | * Takes the documents returned by the aggregation pipeline and writes them |
||
353 | * to a specified collection. This must be the last stage in the pipeline. |
||
354 | * |
||
355 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/out/ |
||
356 | */ |
||
357 | 6 | public function out(string $from) : Stage\Out |
|
363 | |||
364 | /** |
||
365 | * Passes along the documents with only the specified fields to the next |
||
366 | * stage in the pipeline. The specified fields can be existing fields from |
||
367 | * the input documents or newly computed fields. |
||
368 | * |
||
369 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/project/ |
||
370 | */ |
||
371 | 4 | public function project() : Stage\Project |
|
377 | |||
378 | /** |
||
379 | * Restricts the contents of the documents based on information stored in |
||
380 | * the documents themselves. |
||
381 | * |
||
382 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/redact/ |
||
383 | */ |
||
384 | 2 | public function redact() : Stage\Redact |
|
390 | |||
391 | /** |
||
392 | * Promotes a specified document to the top level and replaces all other |
||
393 | * fields. |
||
394 | * |
||
395 | * The operation replaces all existing fields in the input document, |
||
396 | * including the _id field. You can promote an existing embedded document to |
||
397 | * the top level, or create a new document for promotion. |
||
398 | * |
||
399 | * @param string|array|null $expression Optional. A replacement expression that |
||
400 | * resolves to a document. |
||
401 | */ |
||
402 | 6 | public function replaceRoot($expression = null) : Stage\ReplaceRoot |
|
408 | |||
409 | /** |
||
410 | * Randomly selects the specified number of documents from its input. |
||
411 | * |
||
412 | * @see https://docs.mongodb.org/manual/reference/operator/aggregation/sample/ |
||
413 | */ |
||
414 | 2 | public function sample(int $size) : Stage\Sample |
|
420 | |||
421 | /** |
||
422 | * Skips over the specified number of documents that pass into the stage and |
||
423 | * passes the remaining documents to the next stage in the pipeline. |
||
424 | * |
||
425 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/skip/ |
||
426 | */ |
||
427 | 2 | public function skip(int $skip) : Stage\Skip |
|
433 | |||
434 | /** |
||
435 | * Sorts all input documents and returns them to the pipeline in sorted |
||
436 | * order. |
||
437 | * |
||
438 | * If sorting by multiple fields, the first argument should be an array of |
||
439 | * field name (key) and order (value) pairs. |
||
440 | * |
||
441 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/sort/ |
||
442 | * |
||
443 | * @param array|string $fieldName Field name or array of field/order pairs |
||
444 | * @param int|string $order Field order (if one field is specified) |
||
445 | */ |
||
446 | 7 | public function sort($fieldName, $order = null) : Stage\Sort |
|
454 | |||
455 | /** |
||
456 | * Groups incoming documents based on the value of a specified expression, |
||
457 | * then computes the count of documents in each distinct group. |
||
458 | * |
||
459 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/sortByCount/ |
||
460 | */ |
||
461 | 3 | public function sortByCount(string $expression) : Stage\SortByCount |
|
467 | |||
468 | /** |
||
469 | * Deconstructs an array field from the input documents to output a document |
||
470 | * for each element. Each output document is the input document with the |
||
471 | * value of the array field replaced by the element. |
||
472 | * |
||
473 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/unwind/ |
||
474 | */ |
||
475 | 7 | public function unwind(string $fieldName) : Stage\Unwind |
|
482 | |||
483 | 61 | protected function addStage(Stage $stage) : Stage |
|
489 | |||
490 | /** |
||
491 | * Applies filters and discriminator queries to the pipeline |
||
492 | */ |
||
493 | 55 | private function applyFilters(array $query) : array |
|
502 | |||
503 | 11 | private function getDocumentPersister() : DocumentPersister |
|
507 | |||
508 | 17 | private function prepareIterator(Cursor $cursor) : Iterator |
|
521 | } |
||
522 |