1 | <?php |
||
33 | class Builder extends BaseBuilder |
||
34 | { |
||
35 | /** |
||
36 | * The DocumentManager instance for this query |
||
37 | * |
||
38 | * @var DocumentManager |
||
39 | */ |
||
40 | private $dm; |
||
41 | |||
42 | /** |
||
43 | * The ClassMetadata instance. |
||
44 | * |
||
45 | * @var \Doctrine\ODM\MongoDB\Mapping\ClassMetadata |
||
46 | */ |
||
47 | private $class; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | private $hydrationClass; |
||
53 | |||
54 | /** |
||
55 | * Create a new aggregation builder. |
||
56 | * |
||
57 | * @param DocumentManager $dm |
||
58 | * @param string $documentName |
||
59 | */ |
||
60 | 18 | public function __construct(DocumentManager $dm, $documentName) |
|
61 | { |
||
62 | 18 | $this->dm = $dm; |
|
63 | 18 | $this->class = $this->dm->getClassMetadata($documentName); |
|
64 | |||
65 | 18 | parent::__construct($this->dm->getDocumentCollection($documentName)); |
|
66 | 18 | } |
|
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | 9 | public function execute($options = []) |
|
72 | { |
||
73 | // Force cursor to be used |
||
74 | 9 | $options = array_merge($options, ['cursor' => true]); |
|
75 | |||
76 | 9 | $cursor = parent::execute($options); |
|
77 | |||
78 | 9 | return $this->prepareCursor($cursor); |
|
|
|||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Set which class to use when hydrating results as document class instances. |
||
83 | * |
||
84 | * @param string $className |
||
85 | * |
||
86 | * @return self |
||
87 | */ |
||
88 | 1 | public function hydrate($className) |
|
89 | { |
||
90 | 1 | $this->hydrationClass = $className; |
|
91 | |||
92 | 1 | return $this; |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * @return QueryExpr |
||
97 | */ |
||
98 | 5 | public function matchExpr() |
|
99 | { |
||
100 | 5 | $expr = new QueryExpr($this->dm); |
|
101 | 5 | $expr->setClassMetadata($this->class); |
|
102 | |||
103 | 5 | return $expr; |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * @return Expr |
||
108 | */ |
||
109 | 4 | public function expr() |
|
110 | { |
||
111 | 4 | return new Expr($this->dm, $this->class); |
|
112 | } |
||
113 | |||
114 | /** |
||
115 | * @return Stage\Match |
||
116 | */ |
||
117 | 4 | public function match() |
|
121 | |||
122 | /** |
||
123 | * @param string $from |
||
124 | * @return Stage\Lookup |
||
125 | */ |
||
126 | 7 | public function lookup($from) |
|
130 | |||
131 | /** |
||
132 | * @param string $from |
||
133 | * @return Stage\Out |
||
134 | */ |
||
135 | 4 | public function out($from) |
|
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | 2 | public function sort($fieldName, $order = null) |
|
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | 3 | public function unwind($fieldName) |
|
157 | |||
158 | /** |
||
159 | * Returns the assembled aggregation pipeline |
||
160 | * |
||
161 | * For pipelines where the first stage is a $geoNear stage, it will apply |
||
162 | * the document filters and discriminator queries to the query portion of |
||
163 | * the geoNear operation. For all other pipelines, it prepends a $match stage |
||
164 | * containing the required query. |
||
165 | * |
||
166 | * @return array |
||
167 | */ |
||
168 | 15 | public function getPipeline() |
|
183 | |||
184 | /** |
||
185 | * Applies filters and discriminator queries to the pipeline |
||
186 | * |
||
187 | * @param array $query |
||
188 | * @return array |
||
189 | */ |
||
190 | 15 | private function applyFilters(array $query) |
|
199 | |||
200 | /** |
||
201 | * @param BaseCommandCursor $cursor |
||
202 | * |
||
203 | * @return CommandCursor |
||
204 | */ |
||
205 | 9 | private function prepareCursor(BaseCommandCursor $cursor) |
|
206 | { |
||
207 | 9 | $class = null; |
|
208 | 9 | if ($this->hydrationClass) { |
|
209 | 1 | $class = $this->dm->getClassMetadata($this->hydrationClass); |
|
210 | } |
||
211 | |||
212 | 9 | return new CommandCursor($cursor, $this->dm->getUnitOfWork(), $class); |
|
213 | } |
||
214 | |||
215 | /** |
||
216 | * @return \Doctrine\ODM\MongoDB\Persisters\DocumentPersister |
||
217 | */ |
||
218 | 3 | private function getDocumentPersister() |
|
222 | } |
||
223 |
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.