1 | <?php |
||
37 | class AlgoliaManager |
||
38 | { |
||
39 | /** |
||
40 | * @var AlgoliaFactory |
||
41 | */ |
||
42 | protected $factory; |
||
43 | |||
44 | /** |
||
45 | * @var AlgoliaConfig |
||
46 | */ |
||
47 | protected $config; |
||
48 | |||
49 | /** |
||
50 | * @var Client |
||
51 | */ |
||
52 | protected $client; |
||
53 | |||
54 | /** |
||
55 | * @var ActiveRecordFactory |
||
56 | */ |
||
57 | protected $activeRecordFactory; |
||
58 | |||
59 | /** |
||
60 | * @var null|string |
||
61 | */ |
||
62 | protected $env; |
||
63 | |||
64 | /** |
||
65 | * Initiates a new AlgoliaManager. |
||
66 | * |
||
67 | * @param Client $client |
||
68 | * @param ActiveRecordFactory $activeRecordFactory |
||
69 | * |
||
70 | */ |
||
71 | 39 | public function __construct(Client $client, ActiveRecordFactory $activeRecordFactory) |
|
76 | |||
77 | /** |
||
78 | * Returns the Algolia Client. |
||
79 | * |
||
80 | * @return Client |
||
81 | */ |
||
82 | 19 | public function getClient() |
|
86 | |||
87 | /** |
||
88 | * Sets the environment for the manager. |
||
89 | * |
||
90 | * @param string $env |
||
91 | */ |
||
92 | 39 | public function setEnv($env) |
|
96 | |||
97 | /** |
||
98 | * Returns the environment for the manager. |
||
99 | * |
||
100 | * @return null|string |
||
101 | */ |
||
102 | 1 | public function getEnv() |
|
106 | |||
107 | /** |
||
108 | * Indexes a searchable model to all indices. |
||
109 | * |
||
110 | * @param SearchableInterface $searchableModel |
||
111 | * |
||
112 | * @return array |
||
113 | */ |
||
114 | 5 | public function pushToIndices(SearchableInterface $searchableModel) |
|
126 | |||
127 | /** |
||
128 | * Indexes multiple searchable models in a batch. The given searchable models must be of the same class. |
||
129 | * |
||
130 | * @param SearchableInterface[] $searchableModels |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | 3 | public function pushMultipleToIndices(array $searchableModels) |
|
146 | |||
147 | /** |
||
148 | * Updates the models data in all indices. |
||
149 | * |
||
150 | * @param SearchableInterface $searchableModel |
||
151 | * |
||
152 | * @return array |
||
153 | */ |
||
154 | 3 | public function updateInIndices(SearchableInterface $searchableModel) |
|
167 | |||
168 | /** |
||
169 | * Updates multiple models data in all indices. The given searchable models must be of the same class. |
||
170 | * |
||
171 | * @param SearchableInterface[] $searchableModels |
||
172 | * |
||
173 | * @return array |
||
174 | */ |
||
175 | 2 | public function updateMultipleInIndices(array $searchableModels) |
|
187 | |||
188 | /** |
||
189 | * Removes a searchable model from indices. |
||
190 | * |
||
191 | * @param SearchableInterface $searchableModel |
||
192 | * |
||
193 | * @return array |
||
194 | * @throws \Exception |
||
195 | */ |
||
196 | 2 | public function removeFromIndices(SearchableInterface $searchableModel) |
|
208 | |||
209 | /** |
||
210 | * Re-indexes the indices safely for the given ActiveRecord Class. |
||
211 | * |
||
212 | * @param string $className The name of the ActiveRecord to be indexed. |
||
213 | * |
||
214 | * @return array |
||
215 | */ |
||
216 | 3 | public function reindex($className) |
|
253 | |||
254 | /** |
||
255 | * Clears the indices for the given Class that implements SearchableInterface. |
||
256 | * |
||
257 | * @param string $className The name of the Class which indices are to be cleared. |
||
258 | * |
||
259 | * @return array |
||
260 | */ |
||
261 | 2 | public function clearIndices($className) |
|
276 | |||
277 | /** |
||
278 | * Dynamically pass methods to the Algolia Client. |
||
279 | * |
||
280 | * @param string $method |
||
281 | * @param array $parameters |
||
282 | * |
||
283 | * @return mixed |
||
284 | */ |
||
285 | 16 | public function __call($method, $parameters) |
|
289 | |||
290 | /** |
||
291 | * Checks if the given class implements SearchableInterface. |
||
292 | * |
||
293 | * @param string $class Either name or instance of the class to be checked. |
||
294 | */ |
||
295 | 5 | private function checkImplementsSearchableInterface($class) |
|
303 | |||
304 | /** |
||
305 | * Initializes indices for the given SearchableModel. |
||
306 | * |
||
307 | * @param SearchableInterface $searchableModel |
||
308 | * |
||
309 | * @return Index[] |
||
310 | */ |
||
311 | 15 | private function initIndices(SearchableInterface $searchableModel) |
|
325 | |||
326 | /** |
||
327 | * Maps an array of searchable models into an Algolia friendly array. Returns also indices for the searchable model |
||
328 | * which the array consists of. |
||
329 | * |
||
330 | * @param SearchableInterface[] $searchableModels |
||
331 | * |
||
332 | * @return array |
||
333 | */ |
||
334 | 5 | private function getIndicesAndAlgoliaRecordsFromSearchableModelArray(array $searchableModels) |
|
353 | } |
||
354 |