1 | <?php |
||
34 | class Builder |
||
35 | { |
||
36 | /** |
||
37 | * The DocumentManager instance for this query |
||
38 | * |
||
39 | * @var DocumentManager |
||
40 | */ |
||
41 | private $dm; |
||
42 | |||
43 | /** |
||
44 | * The ClassMetadata instance. |
||
45 | * |
||
46 | * @var \Doctrine\ODM\MongoDB\Mapping\ClassMetadata |
||
47 | */ |
||
48 | private $class; |
||
49 | |||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | private $hydrationClass; |
||
54 | |||
55 | /** |
||
56 | * The Collection instance. |
||
57 | * |
||
58 | * @var Collection |
||
59 | */ |
||
60 | private $collection; |
||
61 | |||
62 | /** |
||
63 | * @var Stage[] |
||
64 | */ |
||
65 | private $stages = []; |
||
66 | |||
67 | /** |
||
68 | * Create a new aggregation builder. |
||
69 | * |
||
70 | * @param DocumentManager $dm |
||
71 | * @param string $documentName |
||
72 | */ |
||
73 | 254 | public function __construct(DocumentManager $dm, $documentName) |
|
79 | |||
80 | /** |
||
81 | * Adds new fields to documents. $addFields outputs documents that contain all |
||
82 | * existing fields from the input documents and newly added fields. |
||
83 | * |
||
84 | * The $addFields stage is equivalent to a $project stage that explicitly specifies |
||
85 | * all existing fields in the input documents and adds the new fields. |
||
86 | * |
||
87 | * If the name of the new field is the same as an existing field name (including _id), |
||
88 | * $addFields overwrites the existing value of that field with the value of the |
||
89 | * specified expression. |
||
90 | * |
||
91 | * @see http://docs.mongodb.com/manual/reference/operator/aggregation/addFields/ |
||
92 | * |
||
93 | * @return Stage\AddFields |
||
94 | */ |
||
95 | 1 | public function addFields() |
|
99 | |||
100 | /** |
||
101 | * Categorizes incoming documents into groups, called buckets, based on a |
||
102 | * specified expression and bucket boundaries. |
||
103 | * |
||
104 | * Each bucket is represented as a document in the output. The document for |
||
105 | * each bucket contains an _id field, whose value specifies the inclusive |
||
106 | * lower bound of the bucket and a count field that contains the number of |
||
107 | * documents in the bucket. The count field is included by default when the |
||
108 | * output is not specified. |
||
109 | * |
||
110 | * @see https://docs.mongodb.com/manual/reference/operator/aggregation/bucket/ |
||
111 | * |
||
112 | * @return Stage\Bucket |
||
113 | */ |
||
114 | 2 | public function bucket() |
|
118 | |||
119 | /** |
||
120 | * Categorizes incoming documents into a specific number of groups, called |
||
121 | * buckets, based on a specified expression. |
||
122 | * |
||
123 | * Bucket boundaries are automatically determined in an attempt to evenly |
||
124 | * distribute the documents into the specified number of buckets. Each |
||
125 | * bucket is represented as a document in the output. The document for each |
||
126 | * bucket contains an _id field, whose value specifies the inclusive lower |
||
127 | * bound and the exclusive upper bound for the bucket, and a count field |
||
128 | * that contains the number of documents in the bucket. The count field is |
||
129 | * included by default when the output is not specified. |
||
130 | * |
||
131 | * @see https://docs.mongodb.com/manual/reference/operator/aggregation/bucketAuto/ |
||
132 | * |
||
133 | * @return Stage\BucketAuto |
||
134 | */ |
||
135 | 2 | public function bucketAuto() |
|
139 | |||
140 | /** |
||
141 | * Returns statistics regarding a collection or view. |
||
142 | * |
||
143 | * $collStats must be the first stage in an aggregation pipeline, or else |
||
144 | * the pipeline returns an error. |
||
145 | * |
||
146 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/collStats/ |
||
147 | * @since 1.5 |
||
148 | * |
||
149 | * @return Stage\CollStats |
||
150 | */ |
||
151 | 1 | public function collStats() |
|
155 | |||
156 | /** |
||
157 | * Returns a document that contains a count of the number of documents input |
||
158 | * to the stage. |
||
159 | * |
||
160 | * @see https://docs.mongodb.com/manual/reference/operator/aggregation/count/ |
||
161 | * |
||
162 | * @return Stage\Count |
||
163 | */ |
||
164 | 1 | public function count($fieldName) |
|
168 | |||
169 | /** |
||
170 | * Executes the aggregation pipeline |
||
171 | * |
||
172 | * @param array $options |
||
173 | * @return Iterator |
||
174 | */ |
||
175 | 17 | public function execute($options = []) |
|
184 | |||
185 | /** |
||
186 | * @return Expr |
||
187 | */ |
||
188 | 147 | public function expr() |
|
192 | |||
193 | /** |
||
194 | * Processes multiple aggregation pipelines within a single stage on the |
||
195 | * same set of input documents. |
||
196 | * |
||
197 | * Each sub-pipeline has its own field in the output document where its |
||
198 | * results are stored as an array of documents. |
||
199 | * |
||
200 | * @return Stage\Facet |
||
201 | */ |
||
202 | 1 | public function facet() |
|
206 | |||
207 | /** |
||
208 | * Outputs documents in order of nearest to farthest from a specified point. |
||
209 | * |
||
210 | * A GeoJSON point may be provided as the first and only argument for |
||
211 | * 2dsphere queries. This single parameter may be a GeoJSON point object or |
||
212 | * an array corresponding to the point's JSON representation. If GeoJSON is |
||
213 | * used, the "spherical" option will default to true. |
||
214 | * |
||
215 | * You can only use this as the first stage of a pipeline. |
||
216 | * |
||
217 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/geoNear/ |
||
218 | * |
||
219 | * @param float|array|Point $x |
||
220 | * @param float $y |
||
221 | * @return Stage\GeoNear |
||
222 | */ |
||
223 | 4 | public function geoNear($x, $y = null) |
|
227 | |||
228 | /** |
||
229 | * Returns the assembled aggregation pipeline |
||
230 | * |
||
231 | * For pipelines where the first stage is a $geoNear stage, it will apply |
||
232 | * the document filters and discriminator queries to the query portion of |
||
233 | * the geoNear operation. For all other pipelines, it prepends a $match stage |
||
234 | * containing the required query. |
||
235 | * |
||
236 | * @return array |
||
237 | */ |
||
238 | 55 | public function getPipeline() |
|
256 | |||
257 | /** |
||
258 | * Returns a certain stage from the pipeline |
||
259 | * |
||
260 | * @param integer $index |
||
261 | * @return Stage |
||
262 | */ |
||
263 | 55 | public function getStage($index) |
|
271 | |||
272 | /** |
||
273 | * Performs a recursive search on a collection, with options for restricting |
||
274 | * the search by recursion depth and query filter. |
||
275 | * |
||
276 | * @see https://docs.mongodb.org/manual/reference/operator/aggregation/graphLookup/ |
||
277 | * |
||
278 | * @param string $from Target collection for the $graphLookup operation to |
||
279 | * search, recursively matching the connectFromField to the connectToField. |
||
280 | * @return Stage\GraphLookup |
||
281 | */ |
||
282 | 10 | public function graphLookup($from) |
|
286 | |||
287 | /** |
||
288 | * Groups documents by some specified expression and outputs to the next |
||
289 | * stage a document for each distinct grouping. |
||
290 | * |
||
291 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/group/ |
||
292 | * |
||
293 | * @return Stage\Group |
||
294 | */ |
||
295 | 4 | public function group() |
|
299 | |||
300 | /** |
||
301 | * Set which class to use when hydrating results as document class instances. |
||
302 | * |
||
303 | * @param string $className |
||
304 | * |
||
305 | * @return self |
||
306 | */ |
||
307 | 4 | public function hydrate($className) |
|
313 | |||
314 | /** |
||
315 | * Returns statistics regarding the use of each index for the collection. |
||
316 | * |
||
317 | * @see https://docs.mongodb.org/manual/reference/operator/aggregation/indexStats/ |
||
318 | * |
||
319 | * @return Stage\IndexStats |
||
320 | */ |
||
321 | 1 | public function indexStats() |
|
325 | |||
326 | /** |
||
327 | * Limits the number of documents passed to the next stage in the pipeline. |
||
328 | * |
||
329 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/limit/ |
||
330 | * |
||
331 | * @param integer $limit |
||
332 | * @return Stage\Limit |
||
333 | */ |
||
334 | 2 | public function limit($limit) |
|
338 | |||
339 | /** |
||
340 | * Performs a left outer join to an unsharded collection in the same |
||
341 | * database to filter in documents from the “joined” collection for |
||
342 | * processing. |
||
343 | * |
||
344 | * @see https://docs.mongodb.org/manual/reference/operator/aggregation/lookup/ |
||
345 | * |
||
346 | * @param string $from |
||
347 | * @return Stage\Lookup |
||
348 | */ |
||
349 | 14 | public function lookup($from) |
|
353 | |||
354 | /** |
||
355 | * Filters the documents to pass only the documents that match the specified |
||
356 | * condition(s) to the next pipeline stage. |
||
357 | * |
||
358 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/match/ |
||
359 | * |
||
360 | * @return Stage\Match |
||
361 | */ |
||
362 | 8 | public function match() |
|
366 | |||
367 | /** |
||
368 | * Returns a query expression to be used in match stages |
||
369 | * |
||
370 | * @return QueryExpr |
||
371 | */ |
||
372 | 60 | public function matchExpr() |
|
379 | |||
380 | /** |
||
381 | * Takes the documents returned by the aggregation pipeline and writes them |
||
382 | * to a specified collection. This must be the last stage in the pipeline. |
||
383 | * |
||
384 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/out/ |
||
385 | * |
||
386 | * @param string $collection |
||
387 | * @return Stage\Out |
||
388 | */ |
||
389 | 6 | public function out($from) |
|
393 | |||
394 | /** |
||
395 | * Passes along the documents with only the specified fields to the next |
||
396 | * stage in the pipeline. The specified fields can be existing fields from |
||
397 | * the input documents or newly computed fields. |
||
398 | * |
||
399 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/project/ |
||
400 | * |
||
401 | * @return Stage\Project |
||
402 | */ |
||
403 | 4 | public function project() |
|
407 | |||
408 | /** |
||
409 | * Restricts the contents of the documents based on information stored in |
||
410 | * the documents themselves. |
||
411 | * |
||
412 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/redact/ |
||
413 | * |
||
414 | * @return Stage\Redact |
||
415 | */ |
||
416 | 2 | public function redact() |
|
420 | |||
421 | /** |
||
422 | * Promotes a specified document to the top level and replaces all other |
||
423 | * fields. |
||
424 | * |
||
425 | * The operation replaces all existing fields in the input document, |
||
426 | * including the _id field. You can promote an existing embedded document to |
||
427 | * the top level, or create a new document for promotion. |
||
428 | * |
||
429 | * @param string|null $expression Optional. A replacement expression that |
||
430 | * resolves to a document. |
||
431 | * |
||
432 | * @return Stage\ReplaceRoot |
||
433 | */ |
||
434 | 6 | public function replaceRoot($expression = null) |
|
438 | |||
439 | /** |
||
440 | * Randomly selects the specified number of documents from its input. |
||
441 | * |
||
442 | * @see https://docs.mongodb.org/manual/reference/operator/aggregation/sample/ |
||
443 | * |
||
444 | * @param integer $size |
||
445 | * @return Stage\Sample |
||
446 | */ |
||
447 | 2 | public function sample($size) |
|
451 | |||
452 | /** |
||
453 | * Skips over the specified number of documents that pass into the stage and |
||
454 | * passes the remaining documents to the next stage in the pipeline. |
||
455 | * |
||
456 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/skip/ |
||
457 | * |
||
458 | * @param integer $skip |
||
459 | * @return Stage\Skip |
||
460 | */ |
||
461 | 2 | public function skip($skip) |
|
465 | |||
466 | /** |
||
467 | * Sorts all input documents and returns them to the pipeline in sorted |
||
468 | * order. |
||
469 | * |
||
470 | * If sorting by multiple fields, the first argument should be an array of |
||
471 | * field name (key) and order (value) pairs. |
||
472 | * |
||
473 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/sort/ |
||
474 | * |
||
475 | * @param array|string $fieldName Field name or array of field/order pairs |
||
476 | * @param integer|string $order Field order (if one field is specified) |
||
477 | * @return Stage\Sort |
||
478 | */ |
||
479 | 7 | public function sort($fieldName, $order = null) |
|
485 | |||
486 | /** |
||
487 | * Groups incoming documents based on the value of a specified expression, |
||
488 | * then computes the count of documents in each distinct group. |
||
489 | * |
||
490 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/sortByCount/ |
||
491 | * |
||
492 | * @param string $expression The expression to group by |
||
493 | * @return Stage\SortByCount |
||
494 | */ |
||
495 | 3 | public function sortByCount($expression) |
|
499 | |||
500 | /** |
||
501 | * Deconstructs an array field from the input documents to output a document |
||
502 | * for each element. Each output document is the input document with the |
||
503 | * value of the array field replaced by the element. |
||
504 | * |
||
505 | * @see http://docs.mongodb.org/manual/reference/operator/aggregation/unwind/ |
||
506 | * |
||
507 | * @param string $fieldName The field to unwind. It is automatically prefixed with the $ sign |
||
508 | * @return Stage\Unwind |
||
509 | */ |
||
510 | 7 | public function unwind($fieldName) |
|
515 | |||
516 | /** |
||
517 | * @param Stage $stage |
||
518 | * @return Stage |
||
519 | */ |
||
520 | 61 | protected function addStage(Stage $stage) |
|
526 | |||
527 | /** |
||
528 | * Applies filters and discriminator queries to the pipeline |
||
529 | * |
||
530 | * @param array $query |
||
531 | * @return array |
||
532 | */ |
||
533 | 55 | private function applyFilters(array $query) |
|
542 | |||
543 | /** |
||
544 | * @return \Doctrine\ODM\MongoDB\Persisters\DocumentPersister |
||
545 | */ |
||
546 | 11 | private function getDocumentPersister() |
|
550 | |||
551 | /** |
||
552 | * @param Cursor $cursor |
||
553 | * |
||
554 | * @return Iterator |
||
555 | */ |
||
556 | 17 | private function prepareIterator(Cursor $cursor): Iterator |
|
569 | } |
||
570 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: