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 | * @var null|string |
||
61 | */ |
||
62 | protected $env; |
||
63 | |||
64 | /** |
||
65 | * Initiates a new AlgoliaManager. |
||
66 | * |
||
67 | * @param AlgoliaFactory $algoliaFactory |
||
68 | * @param ActiveRecordFactory $activeRecordFactory |
||
69 | * @param array $config Configurations for the Algolia Client. |
||
70 | */ |
||
71 | 26 | public function __construct(AlgoliaFactory $algoliaFactory, ActiveRecordFactory $activeRecordFactory, array $config = []) |
|
77 | |||
78 | /** |
||
79 | * Returns the Algolia Client. |
||
80 | * |
||
81 | * @return Client |
||
82 | */ |
||
83 | 9 | public function getClient() |
|
91 | |||
92 | /** |
||
93 | * Returns the config array. |
||
94 | * |
||
95 | * @return array |
||
96 | */ |
||
97 | 2 | public function getConfig() |
|
101 | |||
102 | /** |
||
103 | * Sets the environment for the manager. |
||
104 | * |
||
105 | * @param string $env |
||
106 | */ |
||
107 | 26 | public function setEnv($env) |
|
111 | |||
112 | /** |
||
113 | * Returns the environment for the manager. |
||
114 | * |
||
115 | * @return null|string |
||
116 | */ |
||
117 | public function getEnv() |
||
121 | |||
122 | /** |
||
123 | * Indexes a searchable model to all indices. |
||
124 | * |
||
125 | * @param SearchableInterface $searchableModel |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | 2 | public function pushToIndices(SearchableInterface $searchableModel) |
|
141 | |||
142 | /** |
||
143 | * Updates the models data in all indices. |
||
144 | * |
||
145 | * @param SearchableInterface $searchableModel |
||
146 | * |
||
147 | * @return array |
||
148 | */ |
||
149 | 2 | public function updateInIndices(SearchableInterface $searchableModel) |
|
162 | |||
163 | /** |
||
164 | * Removes a searchable model from indices. |
||
165 | * |
||
166 | * @param SearchableInterface $searchableModel |
||
167 | * |
||
168 | * @return array |
||
169 | * @throws \Exception |
||
170 | */ |
||
171 | 2 | public function removeFromIndices(SearchableInterface $searchableModel) |
|
183 | |||
184 | /** |
||
185 | * Re-indexes the indices safely for the given ActiveRecord Class. |
||
186 | * |
||
187 | * @param string $className The name of the ActiveRecord to be indexed. |
||
188 | * |
||
189 | * @return array |
||
190 | */ |
||
191 | 3 | public function reindex($className) |
|
229 | |||
230 | /** |
||
231 | * Clears the indices for the given Class that implements SearchableInterface. |
||
232 | * |
||
233 | * @param string $className The name of the Class which indices are to be cleared. |
||
234 | * |
||
235 | * @return array |
||
236 | */ |
||
237 | 2 | public function clearIndices($className) |
|
252 | |||
253 | /** |
||
254 | * Dynamically pass methods to the Algolia Client. |
||
255 | * |
||
256 | * @param string $method |
||
257 | * @param array $parameters |
||
258 | * |
||
259 | * @return mixed |
||
260 | */ |
||
261 | 8 | public function __call($method, $parameters) |
|
265 | |||
266 | /** |
||
267 | * Checks if the given class implements SearchableInterface. |
||
268 | * |
||
269 | * @param string $class Either name or instance of the class to be checked. |
||
270 | */ |
||
271 | 5 | private function checkImplementsSearchableInterface($class) |
|
279 | |||
280 | /** |
||
281 | * Initializes indices for the given SearchableModel. |
||
282 | * |
||
283 | * @param SearchableInterface $searchableModel |
||
284 | * |
||
285 | * @return Index[] |
||
286 | */ |
||
287 | 7 | private function initIndices(SearchableInterface $searchableModel) |
|
303 | } |
||
304 |