class ClientManager in Elasticsearch Connector 8.2
Same name and namespace in other branches
- 8.7 src/ElasticSearch/ClientManager.php \Drupal\elasticsearch_connector\ElasticSearch\ClientManager
- 8.5 src/ElasticSearch/ClientManager.php \Drupal\elasticsearch_connector\ElasticSearch\ClientManager
- 8.6 src/ElasticSearch/ClientManager.php \Drupal\elasticsearch_connector\ElasticSearch\ClientManager
Class ClientManager.
Hierarchy
- class \Drupal\elasticsearch_connector\ElasticSearch\ClientManager implements ClientManagerInterface
Expanded class hierarchy of ClientManager
1 string reference to 'ClientManager'
1 service uses ClientManager
File
- src/
ElasticSearch/ ClientManager.php, line 12
Namespace
Drupal\elasticsearch_connector\ElasticSearchView source
class ClientManager implements ClientManagerInterface {
/** @var \nodespark\DESConnector\ClientInterface[] */
protected $clients = [];
/**
* @var ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The class that implements
* \nodespark\DESConnector\ClientFactoryInterface.
*
* @var string
*/
protected $clientManagerFactory;
/**
* ConnectorManager constructor.
*
* @param ModuleHandlerInterface $module_handler
*/
public function __construct(ModuleHandlerInterface $module_handler, ClientFactoryInterface $clientManagerFactory) {
$this->moduleHandler = $module_handler;
$this->clientManagerFactory = $clientManagerFactory;
}
/**
* Get the Elasticsearch client required by the functionality.
*
* @param Cluster $cluster
*
* @return \nodespark\DESConnector\ClientInterface
*
* @throws \Exception
*/
public function getClientForCluster(Cluster $cluster) {
$hosts = [
[
'url' => $cluster->url,
'options' => $cluster->options,
],
];
$hash = json_encode($hosts);
if (!isset($this->clients[$hash])) {
$options = array(
'hosts' => array(
$cluster
->getRawUrl(),
),
'options' => array(),
'curl' => array(),
);
if ($cluster->options['use_authentication']) {
$options['auth'] = [
$cluster->url => [
'username' => $cluster->options['username'],
'password' => $cluster->options['password'],
'method' => $cluster->options['authentication_type'],
],
];
}
$this->moduleHandler
->alter('elasticsearch_connector_load_library_options', $options);
$this->clients[$hash] = $this->clientManagerFactory
->create($options);
}
return $this->clients[$hash];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ClientManager:: |
protected | property | The class that implements \nodespark\DESConnector\ClientFactoryInterface. | |
ClientManager:: |
protected | property | @var \nodespark\DESConnector\ClientInterface[] | |
ClientManager:: |
protected | property | ||
ClientManager:: |
public | function |
Get the Elasticsearch client required by the functionality. Overrides ClientManagerInterface:: |
|
ClientManager:: |
public | function |
ConnectorManager constructor. Overrides ClientManagerInterface:: |