1 | <?php |
||
32 | class Builder extends BaseBuilder |
||
33 | { |
||
34 | /** |
||
35 | * The DocumentManager instance for this query |
||
36 | * |
||
37 | * @var DocumentManager |
||
38 | */ |
||
39 | private $dm; |
||
40 | |||
41 | /** |
||
42 | * The ClassMetadata instance. |
||
43 | * |
||
44 | * @var \Doctrine\ODM\MongoDB\Mapping\ClassMetadata |
||
45 | */ |
||
46 | private $class; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | private $hydrationClass; |
||
52 | |||
53 | /** |
||
54 | * Create a new aggregation builder. |
||
55 | * |
||
56 | * @param DocumentManager $dm |
||
57 | * @param string $documentName |
||
58 | */ |
||
59 | 31 | public function __construct(DocumentManager $dm, $documentName) |
|
60 | { |
||
61 | 31 | $this->dm = $dm; |
|
62 | 31 | $this->class = $this->dm->getClassMetadata($documentName); |
|
63 | |||
64 | 31 | parent::__construct($this->dm->getDocumentCollection($documentName)); |
|
65 | 31 | } |
|
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | 12 | public function execute($options = []) |
|
71 | { |
||
72 | // Force cursor to be used |
||
73 | 12 | $options = array_merge($options, ['cursor' => true]); |
|
74 | |||
75 | 12 | $cursor = parent::execute($options); |
|
76 | |||
77 | 12 | return $this->prepareCursor($cursor); |
|
|
|||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Set which class to use when hydrating results as document class instances. |
||
82 | * |
||
83 | * @param string $className |
||
84 | * |
||
85 | * @return self |
||
86 | */ |
||
87 | 1 | public function hydrate($className) |
|
88 | { |
||
89 | 1 | $this->hydrationClass = $className; |
|
90 | |||
91 | 1 | return $this; |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * @return QueryExpr |
||
96 | */ |
||
97 | 7 | public function matchExpr() |
|
98 | { |
||
99 | 7 | $expr = new QueryExpr($this->dm); |
|
100 | 7 | $expr->setClassMetadata($this->class); |
|
101 | |||
102 | 7 | return $expr; |
|
103 | } |
||
104 | |||
105 | /** |
||
106 | * @return Expr |
||
107 | */ |
||
108 | 10 | public function expr() |
|
109 | { |
||
110 | 10 | return new Expr($this->dm, $this->class); |
|
111 | } |
||
112 | |||
113 | /** |
||
114 | * @return Stage\Bucket |
||
115 | */ |
||
116 | 1 | public function bucket() |
|
120 | |||
121 | /** |
||
122 | * @return Stage\BucketAuto |
||
123 | */ |
||
124 | 1 | public function bucketAuto() |
|
128 | |||
129 | /** |
||
130 | * @param string $from |
||
131 | * |
||
132 | * @return Stage\GraphLookup |
||
133 | */ |
||
134 | public function graphLookup($from) |
||
135 | { |
||
136 | return $this->addStage(new Stage\GraphLookup($this, $from, $this->dm, $this->class)); |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * @return Stage\Match |
||
141 | */ |
||
142 | 6 | public function match() |
|
146 | |||
147 | /** |
||
148 | * @param string $from |
||
149 | * @return Stage\Lookup |
||
150 | */ |
||
151 | 13 | public function lookup($from) |
|
155 | |||
156 | /** |
||
157 | * @param string $from |
||
158 | * @return Stage\Out |
||
159 | */ |
||
160 | 4 | public function out($from) |
|
164 | |||
165 | /** |
||
166 | * @param string|null $expression Optional. A replacement expression that |
||
167 | * resolves to a document. |
||
168 | * @return Stage\ReplaceRoot |
||
169 | */ |
||
170 | 6 | public function replaceRoot($expression = null) |
|
174 | |||
175 | /** |
||
176 | * @return Stage\SortByCount |
||
177 | */ |
||
178 | 1 | public function sortByCount($expression) |
|
182 | |||
183 | /** |
||
184 | * {@inheritdoc} |
||
185 | */ |
||
186 | 2 | public function sort($fieldName, $order = null) |
|
191 | |||
192 | /** |
||
193 | * {@inheritdoc} |
||
194 | */ |
||
195 | 4 | public function unwind($fieldName) |
|
200 | |||
201 | /** |
||
202 | * Returns the assembled aggregation pipeline |
||
203 | * |
||
204 | * For pipelines where the first stage is a $geoNear stage, it will apply |
||
205 | * the document filters and discriminator queries to the query portion of |
||
206 | * the geoNear operation. For all other pipelines, it prepends a $match stage |
||
207 | * containing the required query. |
||
208 | * |
||
209 | * @return array |
||
210 | */ |
||
211 | 22 | public function getPipeline() |
|
226 | |||
227 | /** |
||
228 | * Applies filters and discriminator queries to the pipeline |
||
229 | * |
||
230 | * @param array $query |
||
231 | * @return array |
||
232 | */ |
||
233 | 22 | private function applyFilters(array $query) |
|
242 | |||
243 | /** |
||
244 | * @param BaseCommandCursor $cursor |
||
245 | * |
||
246 | * @return CommandCursor |
||
247 | */ |
||
248 | 12 | private function prepareCursor(BaseCommandCursor $cursor) |
|
249 | { |
||
250 | 12 | $class = null; |
|
251 | 12 | if ($this->hydrationClass) { |
|
252 | 1 | $class = $this->dm->getClassMetadata($this->hydrationClass); |
|
253 | } |
||
254 | |||
255 | 12 | return new CommandCursor($cursor, $this->dm->getUnitOfWork(), $class); |
|
256 | } |
||
257 | |||
258 | /** |
||
259 | * @return \Doctrine\ODM\MongoDB\Persisters\DocumentPersister |
||
260 | */ |
||
261 | 4 | private function getDocumentPersister() |
|
265 | } |
||
266 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.