public static function DESConnector81::getInstance in Elasticsearch Connector 8
Initializes the needed client.
TODO: We need to check the available options for the ClientBuilder and set them after the alter hook.
Parameters
array $hosts: The URLs of the Elasticsearch hosts.
Return value
Client
Overrides DESConnector::getInstance
1 call to DESConnector81::getInstance()
- DESConnector::getInstance in src/
DESConnector/ DESConnector.php - Initializes the needed client.
File
- src/
DESConnector/ DESConnector81.php, line 66 - Provides Elasticsearch Client for Drupal's Elasticsearch Connector module.
Class
- DESConnector81
- Drupal Elasticsearch Interface.
Namespace
Drupal\elasticsearch_connector\DESConnectorCode
public static function getInstance(array $hosts) {
$hash_hosts = array();
foreach ($hosts as $host) {
$hash_hosts[] = $host['url'];
}
$hash = md5(implode(':', $hash_hosts));
if (!isset($instances[$hash])) {
foreach ($hosts as $host) {
$cluster_url = self::buildClusterUrl($host['url'], $host['options']);
$options['hosts'][] = $cluster_url;
self::setAuthentication($options, $host);
}
// TODO: Remove this from the abstraction!
// It should be passed via parameter.
\Drupal::moduleHandler()
->alter('elasticsearch_connector_load_library_options', $options);
$builder = new Client($options);
$instances[$hash] = new DESConnector81($builder);
}
return $instances[$hash];
}