1 | <?php |
||
42 | abstract class AbstractFinder implements FinderInterface, ModelAwareInterface |
||
43 | { |
||
44 | |||
45 | use ModelAwareTrait; |
||
46 | |||
47 | /** |
||
48 | * Whenever to use cursors |
||
49 | * @var bool |
||
50 | */ |
||
51 | private $useCursor = false; |
||
52 | |||
53 | // <editor-fold defaultstate="collapsed" desc="Required getters/setters"> |
||
54 | /** |
||
55 | * @see FinderHelpers |
||
56 | * @return FinderAdapterInterface|MongoAdapter |
||
57 | */ |
||
58 | abstract public function getAdapter(); |
||
59 | |||
60 | /** |
||
61 | * @see FinderHelpers |
||
62 | * @return ScopeManagerInterface |
||
63 | */ |
||
64 | abstract public function getScopeManager(); |
||
65 | |||
66 | /** |
||
67 | * @see FinderHelpers |
||
68 | * @return FinderEventsInterface |
||
69 | */ |
||
70 | abstract public function getFinderEvents(); |
||
71 | |||
72 | /** |
||
73 | * @see FinderHelpers |
||
74 | * @return ProfilerInterface |
||
75 | */ |
||
76 | abstract public function getProfiler(); |
||
77 | |||
78 | /** |
||
79 | * @see FinderHelpers |
||
80 | * @return static |
||
81 | */ |
||
82 | abstract public function setAdapter(FinderAdapterInterface $adapter); |
||
83 | |||
84 | /** |
||
85 | * @see FinderHelpers |
||
86 | * @return static |
||
87 | */ |
||
88 | abstract public function setScopeManager(ScopeManagerInterface $scopeManager); |
||
89 | |||
90 | /** |
||
91 | * @see FinderHelpers |
||
92 | * @return static |
||
93 | */ |
||
94 | abstract public function setFinderEvents(FinderEventsInterface $finderEvents); |
||
95 | |||
96 | /** |
||
97 | * @see FinderHelpers |
||
98 | * @return static |
||
99 | */ |
||
100 | abstract public function setProfiler(ProfilerInterface $profiler); |
||
101 | // </editor-fold> |
||
102 | |||
103 | /** |
||
104 | * Finds a single Document with the specified condition. |
||
105 | * |
||
106 | * @param array|CriteriaInterface $criteria query criteria. |
||
107 | * @return AnnotatedInterface |
||
108 | * @Ignored |
||
109 | */ |
||
110 | 81 | public function find($criteria = null) |
|
120 | |||
121 | /** |
||
122 | * Finds document with the specified primary key. Primary key by default |
||
123 | * is defined by `_id` field. But could be any other. For simple (one column) |
||
124 | * keys use it's value. |
||
125 | * |
||
126 | * For composite use key-value with column names as keys |
||
127 | * and values for values. |
||
128 | * |
||
129 | * Example for simple pk: |
||
130 | * ```php |
||
131 | * $pk = '51b616fcc0986e30026d0748' |
||
132 | * ``` |
||
133 | * |
||
134 | * Composite pk: |
||
135 | * ```php |
||
136 | * $pk = [ |
||
137 | * 'mainPk' => 1, |
||
138 | * 'secondaryPk' => 2 |
||
139 | * ]; |
||
140 | * ``` |
||
141 | * |
||
142 | * @param mixed $pkValue primary key value. Use array for composite key. |
||
143 | * @param array|CriteriaInterface $criteria |
||
144 | * @return AnnotatedInterface|null |
||
145 | * @Ignored |
||
146 | */ |
||
147 | 58 | public function findByPk($pkValue, $criteria = null) |
|
153 | |||
154 | /** |
||
155 | * Finds document with the specified attributes. |
||
156 | * Attributes should be specified as key-value pairs. |
||
157 | * This allows easier syntax for simple queries. |
||
158 | * |
||
159 | * Example: |
||
160 | * ```php |
||
161 | * $attributes = [ |
||
162 | * 'name' => 'John', |
||
163 | * 'title' => 'dr' |
||
164 | * ]; |
||
165 | * ``` |
||
166 | * |
||
167 | * @param mixed[] Array of stributes and values in form of ['attributeName' => 'value'] |
||
168 | * @return AnnotatedInterface|null |
||
169 | */ |
||
170 | 2 | public function findByAttributes(array $attributes) |
|
179 | |||
180 | /** |
||
181 | * Finds all documents satisfying the specified condition. |
||
182 | * See {@link find()} for detailed explanation about $condition and $params. |
||
183 | * |
||
184 | * @param array|CriteriaInterface $criteria query criteria. |
||
185 | * @return AnnotatedInterface[]|Cursor |
||
186 | */ |
||
187 | 25 | public function findAll($criteria = null) |
|
225 | |||
226 | /** |
||
227 | * Finds all documents with the specified attributes. |
||
228 | * |
||
229 | * @param mixed[] Array of stributes and values in form of ['attributeName' => 'value'] |
||
230 | * @return AnnotatedInterface[]|Cursor - Array or cursor of Documents |
||
231 | * @since v1.0 |
||
232 | */ |
||
233 | 1 | public function findAllByAttributes(array $attributes) |
|
243 | |||
244 | /** |
||
245 | * Finds all documents with the specified primary keys. |
||
246 | * In MongoDB world every document has '_id' unique field, so with this method that |
||
247 | * field is in use as PK by default. |
||
248 | * See {@link find()} for detailed explanation about $condition. |
||
249 | * |
||
250 | * @param mixed $pkValues primary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value). |
||
251 | * @param array|CriteriaInterface $criteria query criteria. |
||
252 | * @return AnnotatedInterface[]|Cursor - Array or cursor of Documents |
||
253 | * @since v1.0 |
||
254 | */ |
||
255 | 7 | public function findAllByPk($pkValues, $criteria = null) |
|
262 | |||
263 | /** |
||
264 | * Counts all documents satisfying the specified condition. |
||
265 | * See {@link find()} for detailed explanation about $condition and $params. |
||
266 | * @param array|CriteriaInterface $criteria query criteria. |
||
267 | * @return integer Count of all documents satisfying the specified condition. |
||
268 | * @since v1.0 |
||
269 | */ |
||
270 | 31 | public function count($criteria = null) |
|
281 | |||
282 | /** |
||
283 | * Counts all documents found by attribute values. |
||
284 | * |
||
285 | * Example: |
||
286 | * ```php |
||
287 | * $attributes = [ |
||
288 | * 'name' => 'John', |
||
289 | * 'title' => 'dr' |
||
290 | * ]; |
||
291 | * ``` |
||
292 | * |
||
293 | * @param mixed[] Array of attributes and values in form of ['attributeName' => 'value'] |
||
294 | * @return int |
||
295 | * @since v1.2.2 |
||
296 | * @Ignored |
||
297 | */ |
||
298 | 1 | public function countByAttributes(array $attributes) |
|
316 | |||
317 | /** |
||
318 | * Checks whether there is document satisfying the specified condition. |
||
319 | * |
||
320 | * @param CriteriaInterface $criteria |
||
321 | * @return bool |
||
322 | */ |
||
323 | 7 | public function exists(CriteriaInterface $criteria = null) |
|
346 | |||
347 | /** |
||
348 | * Resets all scopes and criteria applied including default scope. |
||
349 | * |
||
350 | * @return Finder |
||
351 | * @since v1.0 |
||
352 | */ |
||
353 | public function resetScope() |
||
358 | |||
359 | /** |
||
360 | * Whenever to use cursor |
||
361 | * @param bool $useCursor |
||
362 | * @return FinderInterface |
||
363 | */ |
||
364 | 108 | public function withCursor($useCursor = true) |
|
369 | |||
370 | 23 | public function isWithCursor() |
|
374 | |||
375 | /** |
||
376 | * Creates an model with the given attributes. |
||
377 | * This method is internally used by the find methods. |
||
378 | * @param mixed[] $data attribute values (column name=>column value) |
||
379 | * @return AnnotatedInterface|null the newly created document. The class of the object is the same as the model class. |
||
380 | * Null is returned if the input data is false. |
||
381 | * @since v1.0 |
||
382 | */ |
||
383 | 95 | protected function populateRecord($data) |
|
397 | |||
398 | /** |
||
399 | * Creates a list of documents based on the input data. |
||
400 | * This method is internally used by the find methods. |
||
401 | * @param Iterator|array $cursor Results found to populate active records. |
||
402 | * @return AnnotatedInterface[] array list of active records. |
||
403 | * @since v1.0 |
||
404 | */ |
||
405 | 22 | private function populateRecords($cursor) |
|
414 | |||
415 | } |
||
416 |