1 | <?php |
||
24 | class Repository |
||
25 | { |
||
26 | /** |
||
27 | * @var Manager |
||
28 | */ |
||
29 | private $manager; |
||
30 | |||
31 | /** |
||
32 | * @var string Fully qualified class name |
||
33 | */ |
||
34 | private $className; |
||
35 | |||
36 | /** |
||
37 | * @var string Elasticsearch type name |
||
38 | */ |
||
39 | private $type; |
||
40 | |||
41 | /** |
||
42 | * Constructor. |
||
43 | * |
||
44 | * @param Manager $manager |
||
45 | * @param string $className |
||
46 | */ |
||
47 | public function __construct($manager, $className) |
||
62 | |||
63 | /** |
||
64 | * Returns elasticsearch manager used in the repository. |
||
65 | * |
||
66 | * @return Manager |
||
67 | */ |
||
68 | public function getManager() |
||
72 | |||
73 | /** |
||
74 | * @return array |
||
75 | */ |
||
76 | public function getType() |
||
80 | |||
81 | /** |
||
82 | * Returns a single document data by ID or null if document is not found. |
||
83 | * |
||
84 | * @param string $id Document ID to find |
||
85 | * |
||
86 | * @return object |
||
87 | */ |
||
88 | public function find($id) |
||
92 | |||
93 | /** |
||
94 | * Finds documents by a set of criteria. |
||
95 | * |
||
96 | * @param array $criteria Example: ['group' => ['best', 'worst'], 'job' => 'medic']. |
||
97 | * @param array|null $orderBy Example: ['name' => 'ASC', 'surname' => 'DESC']. |
||
98 | * @param int|null $limit Example: 5. |
||
99 | * @param int|null $offset Example: 30. |
||
100 | * |
||
101 | * @return array|DocumentIterator The objects. |
||
102 | */ |
||
103 | public function findBy( |
||
130 | |||
131 | /** |
||
132 | * Finds a single document by a set of criteria. |
||
133 | * |
||
134 | * @param array $criteria Example: ['group' => ['best', 'worst'], 'job' => 'medic']. |
||
135 | * @param array|null $orderBy Example: ['name' => 'ASC', 'surname' => 'DESC']. |
||
136 | * |
||
137 | * @return object|null The object. |
||
138 | */ |
||
139 | public function findOneBy(array $criteria, array $orderBy = []) |
||
145 | |||
146 | /** |
||
147 | * Returns search instance. |
||
148 | * |
||
149 | * @return Search |
||
150 | */ |
||
151 | public function createSearch() |
||
155 | |||
156 | /** |
||
157 | * Executes given search. |
||
158 | * |
||
159 | * @param Search $search |
||
160 | * @param string $resultsType |
||
161 | * |
||
162 | * @return DocumentIterator|RawIterator|array |
||
163 | * |
||
164 | * @throws \Exception |
||
165 | */ |
||
166 | public function execute(Search $search, $resultsType = Result::RESULTS_OBJECT) |
||
170 | |||
171 | /** |
||
172 | * Counts documents by given search. |
||
173 | * |
||
174 | * @param Search $search |
||
175 | * @param array $params |
||
176 | * @param bool $returnRaw If set true returns raw response gotten from client. |
||
177 | * |
||
178 | * @return int|array |
||
179 | */ |
||
180 | public function count(Search $search, array $params = [], $returnRaw = false) |
||
201 | |||
202 | /** |
||
203 | * Delete by query. |
||
204 | * |
||
205 | * @param Search $search |
||
206 | * |
||
207 | * @return array |
||
208 | */ |
||
209 | public function deleteByQuery(Search $search) |
||
222 | |||
223 | /** |
||
224 | * Removes a single document data by ID. |
||
225 | * |
||
226 | * @param string $id Document ID to remove. |
||
227 | * |
||
228 | * @return array |
||
229 | * |
||
230 | * @throws \LogicException |
||
231 | */ |
||
232 | public function remove($id) |
||
244 | |||
245 | /** |
||
246 | * Partial document update. |
||
247 | * |
||
248 | * @param string $id Document id to update. |
||
249 | * @param array $fields Fields array to update. |
||
250 | * @param string $script Groovy script to update fields. |
||
251 | * @param array $params Additional parameters to pass to the client. |
||
252 | * |
||
253 | * @return array |
||
254 | */ |
||
255 | public function update($id, array $fields = [], $script = null, array $params = []) |
||
276 | |||
277 | /** |
||
278 | * Resolves elasticsearch type by class name. |
||
279 | * |
||
280 | * @param string $className |
||
281 | * |
||
282 | * @return array |
||
283 | */ |
||
284 | private function resolveType($className) |
||
288 | |||
289 | /** |
||
290 | * Returns fully qualified class name. |
||
291 | * |
||
292 | * @return string |
||
293 | */ |
||
294 | public function getClassName() |
||
298 | } |
||
299 |