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) |
||
63 | |||
64 | /** |
||
65 | * Returns elasticsearch manager used in the repository. |
||
66 | * |
||
67 | * @return Manager |
||
68 | */ |
||
69 | public function getManager() |
||
73 | |||
74 | /** |
||
75 | * @return array |
||
76 | */ |
||
77 | public function getType() |
||
81 | |||
82 | /** |
||
83 | * Returns a single document data by ID or null if document is not found. |
||
84 | * |
||
85 | * @param string $id Document ID to find |
||
86 | * |
||
87 | * @return object |
||
88 | */ |
||
89 | public function find($id) |
||
93 | |||
94 | /** |
||
95 | * Finds documents by a set of criteria. |
||
96 | * |
||
97 | * @param array $criteria Example: ['group' => ['best', 'worst'], 'job' => 'medic']. |
||
98 | * @param array|null $orderBy Example: ['name' => 'ASC', 'surname' => 'DESC']. |
||
99 | * @param int|null $limit Example: 5. |
||
100 | * @param int|null $offset Example: 30. |
||
101 | * |
||
102 | * @return array|DocumentIterator The objects. |
||
103 | */ |
||
104 | public function findBy( |
||
131 | |||
132 | /** |
||
133 | * Finds a single document by a set of criteria. |
||
134 | * |
||
135 | * @param array $criteria Example: ['group' => ['best', 'worst'], 'job' => 'medic']. |
||
136 | * @param array|null $orderBy Example: ['name' => 'ASC', 'surname' => 'DESC']. |
||
137 | * |
||
138 | * @return object|null The object. |
||
139 | */ |
||
140 | public function findOneBy(array $criteria, array $orderBy = []) |
||
146 | |||
147 | /** |
||
148 | * Returns search instance. |
||
149 | * |
||
150 | * @return Search |
||
151 | */ |
||
152 | public function createSearch() |
||
156 | |||
157 | /** |
||
158 | * Executes given search. |
||
159 | * |
||
160 | * @param Search $search |
||
161 | * @param string $resultsType |
||
162 | * |
||
163 | * @return DocumentIterator|RawIterator|array |
||
164 | * |
||
165 | * @throws \Exception |
||
166 | */ |
||
167 | public function execute(Search $search, $resultsType = Result::RESULTS_OBJECT) |
||
171 | |||
172 | /** |
||
173 | * Counts documents by given search. |
||
174 | * |
||
175 | * @param Search $search |
||
176 | * @param array $params |
||
177 | * @param bool $returnRaw If set true returns raw response gotten from client. |
||
178 | * |
||
179 | * @return int|array |
||
180 | */ |
||
181 | public function count(Search $search, array $params = [], $returnRaw = false) |
||
202 | |||
203 | /** |
||
204 | * Delete by query. |
||
205 | * |
||
206 | * @param Search $search |
||
207 | * |
||
208 | * @return array |
||
209 | */ |
||
210 | public function deleteByQuery(Search $search) |
||
223 | |||
224 | /** |
||
225 | * Removes a single document data by ID. |
||
226 | * |
||
227 | * @param string $id Document ID to remove. |
||
228 | * |
||
229 | * @return array |
||
230 | * |
||
231 | * @throws \LogicException |
||
232 | */ |
||
233 | public function remove($id) |
||
245 | |||
246 | /** |
||
247 | * Partial document update. |
||
248 | * |
||
249 | * @param string $id Document id to update. |
||
250 | * @param array $fields Fields array to update. |
||
251 | * @param string $script Groovy script to update fields. |
||
252 | * @param array $params Additional parameters to pass to the client. |
||
253 | * |
||
254 | * @return array |
||
255 | */ |
||
256 | public function update($id, array $fields = [], $script = null, array $params = []) |
||
277 | |||
278 | /** |
||
279 | * Resolves elasticsearch type by class name. |
||
280 | * |
||
281 | * @param string $className |
||
282 | * |
||
283 | * @return array |
||
284 | */ |
||
285 | private function resolveType($className) |
||
289 | |||
290 | /** |
||
291 | * Returns fully qualified class name. |
||
292 | * |
||
293 | * @return string |
||
294 | */ |
||
295 | public function getClassName() |
||
299 | } |
||
300 |