1 | <?php |
||
37 | class AlgoliaManager |
||
38 | { |
||
39 | /** |
||
40 | * @var AlgoliaFactory |
||
41 | */ |
||
42 | protected $factory; |
||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $config; |
||
48 | |||
49 | /** |
||
50 | * @var null|Client |
||
51 | */ |
||
52 | protected $client; |
||
53 | |||
54 | /** |
||
55 | * @var ActiveRecordFactory |
||
56 | */ |
||
57 | protected $activeRecordFactory; |
||
58 | |||
59 | /** |
||
60 | * Initiates a new AlgoliaManager. |
||
61 | * |
||
62 | * @param AlgoliaFactory $algoliaFactory |
||
63 | * @param ActiveRecordFactory $activeRecordFactory |
||
64 | * @param array $config Configurations for the Algolia Client. |
||
65 | */ |
||
66 | 24 | public function __construct(AlgoliaFactory $algoliaFactory, ActiveRecordFactory $activeRecordFactory, array $config = []) |
|
72 | |||
73 | /** |
||
74 | * Returns the Algolia Client. |
||
75 | * |
||
76 | * @return Client |
||
77 | */ |
||
78 | 7 | public function getClient() |
|
86 | |||
87 | /** |
||
88 | * Returns the config array. |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | 2 | public function getConfig() |
|
96 | |||
97 | /** |
||
98 | * Indexes a searchable model to all indices. |
||
99 | * |
||
100 | * @param SearchableInterface $searchableModel |
||
101 | * |
||
102 | * @return array |
||
103 | */ |
||
104 | 1 | public function pushToIndices(SearchableInterface $searchableModel) |
|
116 | |||
117 | /** |
||
118 | * Updates the models data in all indices. |
||
119 | * |
||
120 | * @param SearchableInterface $searchableModel |
||
121 | * |
||
122 | * @return array |
||
123 | */ |
||
124 | 1 | public function updateInIndices(SearchableInterface $searchableModel) |
|
137 | |||
138 | /** |
||
139 | * Removes a searchable model from indices. |
||
140 | * |
||
141 | * @param SearchableInterface $searchableModel |
||
142 | * |
||
143 | * @return array |
||
144 | * @throws \Exception |
||
145 | */ |
||
146 | 1 | public function removeFromIndices(SearchableInterface $searchableModel) |
|
158 | |||
159 | /** |
||
160 | * Re-indexes the indices safely for the given ActiveRecord Class. |
||
161 | * |
||
162 | * @param string $className The name of the ActiveRecord to be indexed. |
||
163 | * |
||
164 | * @return array |
||
165 | */ |
||
166 | 2 | public function reindex($className) |
|
197 | |||
198 | /** |
||
199 | * Clears the indices for the given Class that implements SearchableInterface. |
||
200 | * |
||
201 | * @param string $className The name of the Class which indices are to be cleared. |
||
202 | * |
||
203 | * @return array |
||
204 | */ |
||
205 | 2 | public function clearIndices($className) |
|
220 | |||
221 | /** |
||
222 | * Dynamically pass methods to the Algolia Client. |
||
223 | * |
||
224 | * @param string $method |
||
225 | * @param array $parameters |
||
226 | * |
||
227 | * @return mixed |
||
228 | */ |
||
229 | 6 | public function __call($method, $parameters) |
|
233 | |||
234 | /** |
||
235 | * Checks if the given class implements SearchableInterface. |
||
236 | * |
||
237 | * @param string $class Either name or instance of the class to be checked. |
||
238 | */ |
||
239 | 4 | private function checkImplementsSearchableInterface($class) |
|
247 | } |
||
248 |