1 | <?php |
||
50 | class AlgoliaManager |
||
51 | { |
||
52 | /** |
||
53 | * Size for the chunks used in reindexing methods. |
||
54 | */ |
||
55 | const CHUNK_SIZE = 500; |
||
56 | |||
57 | /** |
||
58 | * @var AlgoliaFactory |
||
59 | */ |
||
60 | protected $factory; |
||
61 | |||
62 | /** |
||
63 | * @var AlgoliaConfig |
||
64 | */ |
||
65 | protected $config; |
||
66 | |||
67 | /** |
||
68 | * @var Client |
||
69 | */ |
||
70 | protected $client; |
||
71 | |||
72 | /** |
||
73 | * @var ActiveRecordFactory |
||
74 | */ |
||
75 | protected $activeRecordFactory; |
||
76 | |||
77 | /** |
||
78 | * @var null|string |
||
79 | */ |
||
80 | protected $env; |
||
81 | |||
82 | /** |
||
83 | 65 | * @var ActiveQueryChunker |
|
84 | */ |
||
85 | private $activeQueryChunker; |
||
86 | |||
87 | /** |
||
88 | 65 | * Initiates a new AlgoliaManager. |
|
89 | 65 | * |
|
90 | 65 | * @param Client $client |
|
91 | 65 | * @param ActiveRecordFactory $activeRecordFactory |
|
92 | * @param ActiveQueryChunker $activeQueryChunker |
||
93 | */ |
||
94 | public function __construct( |
||
103 | |||
104 | /** |
||
105 | * Returns the Algolia Client. |
||
106 | * |
||
107 | * @return Client |
||
108 | 65 | */ |
|
109 | public function getClient() |
||
113 | |||
114 | /** |
||
115 | * Sets the environment for the manager. |
||
116 | * |
||
117 | * @param string $env |
||
118 | 1 | */ |
|
119 | public function setEnv($env) |
||
123 | |||
124 | /** |
||
125 | * Returns the environment for the manager. |
||
126 | * |
||
127 | * @return null|string |
||
128 | */ |
||
129 | public function getEnv() |
||
133 | 10 | ||
134 | /** |
||
135 | 10 | * Indexes a searchable model to all indices. |
|
136 | 10 | * |
|
137 | 10 | * @param SearchableInterface $searchableModel |
|
138 | 10 | * |
|
139 | * @return array |
||
140 | 10 | */ |
|
141 | public function pushToIndices(SearchableInterface $searchableModel) |
||
150 | 5 | ||
151 | /** |
||
152 | 5 | * Indexes multiple searchable models in a batch. The given searchable models must be of the same class. |
|
153 | 2 | * |
|
154 | * @param SearchableInterface[] $searchableModels |
||
155 | 2 | * |
|
156 | * @return array |
||
157 | 2 | */ |
|
158 | public function pushMultipleToIndices(array $searchableModels) |
||
167 | |||
168 | /** |
||
169 | * Updates the models data in all indices. |
||
170 | * |
||
171 | * @param SearchableInterface $searchableModel |
||
172 | 3 | * |
|
173 | * @return array |
||
174 | 3 | */ |
|
175 | 3 | public function updateInIndices(SearchableInterface $searchableModel) |
|
185 | |||
186 | /** |
||
187 | * Updates multiple models data in all indices. The given searchable models must be of the same class. |
||
188 | * |
||
189 | * @param SearchableInterface[] $searchableModels |
||
190 | * |
||
191 | * @return array |
||
192 | */ |
||
193 | 4 | public function updateMultipleInIndices(array $searchableModels) |
|
202 | 2 | ||
203 | 2 | /** |
|
204 | * Removes a searchable model from indices. |
||
205 | 2 | * |
|
206 | * @param SearchableInterface $searchableModel |
||
207 | * |
||
208 | * @return array |
||
209 | * @throws \InvalidArgumentException |
||
210 | */ |
||
211 | public function removeFromIndices(SearchableInterface $searchableModel) |
||
220 | |||
221 | 3 | /** |
|
222 | 3 | * Removes multiple models from all indices. The given searchable models must be of the same class. |
|
223 | 3 | * |
|
224 | 3 | * @param array $searchableModels |
|
225 | * |
||
226 | 3 | * @return array |
|
227 | * @throws \InvalidArgumentException |
||
228 | */ |
||
229 | public function removeMultipleFromIndices(array $searchableModels) |
||
241 | |||
242 | 2 | /** |
|
243 | 2 | * Re-indexes the indices safely for the given ActiveRecord Class. |
|
244 | * |
||
245 | 2 | * @param string $className The name of the ActiveRecord to be indexed |
|
246 | * |
||
247 | 2 | * @return array |
|
248 | */ |
||
249 | 2 | public function reindex($className) |
|
269 | 3 | ||
270 | /** |
||
271 | 3 | * Re-indexes the related indices for the given array only with the objects from the given array. |
|
272 | * The given array must consist of Searchable objects of same class. |
||
273 | 3 | * |
|
274 | * @param SearchableInterface[] $searchableModels |
||
275 | * |
||
276 | 3 | * @throws \InvalidArgumentException |
|
277 | 3 | * @return array |
|
278 | */ |
||
279 | 3 | public function reindexOnly(array $searchableModels) |
|
288 | |||
289 | /** |
||
290 | * Re-indexes the related indices for the given ActiveQueryInterface. |
||
291 | * The result of the given ActiveQuery must consist from Searchable models of the same class. |
||
292 | * |
||
293 | * @param ActiveQueryInterface $activeQuery |
||
294 | * |
||
295 | 3 | * @return array |
|
296 | */ |
||
297 | 3 | public function reindexByActiveQuery(ActiveQueryInterface $activeQuery) |
|
320 | |||
321 | 5 | /** |
|
322 | 5 | * Clears the indices for the given Class that implements SearchableInterface. |
|
323 | 5 | * |
|
324 | * @param string $className The name of the Class which indices are to be cleared. |
||
325 | 5 | * |
|
326 | * @throws \InvalidArgumentException |
||
327 | * @return array |
||
328 | */ |
||
329 | 2 | public function clearIndices($className) |
|
340 | 2 | ||
341 | 2 | /** |
|
342 | * @param string $className The name of the class which is to be searched. |
||
343 | 2 | * @param string $query |
|
344 | * @param null|array $searchParameters Optional search parameters given as an associative array. |
||
345 | * |
||
346 | * @link https://github.com/algolia/algoliasearch-client-php#search-parameters Allowed search parameters. |
||
347 | * |
||
348 | * @return array |
||
349 | */ |
||
350 | public function search($className, $query, array $searchParameters = null) |
||
361 | 1 | ||
362 | /** |
||
363 | 1 | * Dynamically pass methods to the Algolia Client. |
|
364 | 1 | * |
|
365 | 1 | * @param string $method |
|
366 | * @param array $parameters |
||
367 | 1 | * |
|
368 | * @return mixed |
||
369 | */ |
||
370 | public function __call($method, $parameters) |
||
374 | |||
375 | /** |
||
376 | * Checks if the given class implements SearchableInterface. |
||
377 | * |
||
378 | * @param string $class Either name or instance of the class to be checked. |
||
379 | 5 | */ |
|
380 | private function checkImplementsSearchableInterface($class) |
||
388 | 4 | ||
389 | 4 | /** |
|
390 | 4 | * Initializes indices for the given SearchableModel. |
|
391 | * |
||
392 | 4 | * @param SearchableInterface $searchableModel |
|
393 | * |
||
394 | * @return Index[] |
||
395 | */ |
||
396 | private function initIndices(SearchableInterface $searchableModel) |
||
408 | |||
409 | /** |
||
410 | * Maps an array of searchable models into an Algolia friendly array. |
||
411 | * |
||
412 | * @param SearchableInterface[] $searchableModels |
||
413 | 29 | * |
|
414 | * @return array |
||
415 | 29 | */ |
|
416 | private function getAlgoliaRecordsFromSearchableModelArray(array $searchableModels) |
||
437 | |||
438 | 25 | /** |
|
439 | 25 | * Reindex atomically the given index with the given records. |
|
440 | * |
||
441 | 25 | * @param Index $index |
|
442 | * @param array $algoliaRecords |
||
443 | * |
||
444 | * @return mixed |
||
445 | */ |
||
446 | private function reindexAtomically(Index $index, array $algoliaRecords) |
||
461 | 17 | ||
462 | 17 | /** |
|
463 | 5 | * Performs actions for given indices returning an array of responses from those actions. |
|
464 | * |
||
465 | * @param Index[] $indices |
||
466 | 17 | * @param callable $callback |
|
467 | 17 | * |
|
468 | * @return array The response as an array in format of ['indexName' => $responseFromAlgoliaClient] |
||
469 | 17 | */ |
|
470 | 17 | private function processIndices($indices, callable $callback) |
|
480 | } |
||
481 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: