class ClientManager in Elasticsearch Connector 8.7
Same name and namespace in other branches
- 8.2 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 file declares its use of ClientManager
- ClientManagerTest.php in tests/
src/ Unit/ ElasticSearch/ ClientManagerTest.php
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 {
/**
* Array of clients keyed by JSON encoded cluster URL and options.
*
* @var \nodespark\DESConnector\ClientInterface[]
*/
protected $clients = [];
/**
* Module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Client manager factory.
*
* @var \nodespark\DESConnector\ClientFactoryInterface
*/
protected $clientManagerFactory;
/**
* {@inheritdoc}
*/
public function __construct(ModuleHandlerInterface $module_handler, ClientFactoryInterface $clientManagerFactory) {
$this->moduleHandler = $module_handler;
$this->clientManagerFactory = $clientManagerFactory;
}
/**
* {@inheritdoc}
*/
public function getClientForCluster(Cluster $cluster) {
$hosts = [
[
'url' => $cluster->url,
'options' => $cluster->options,
],
];
$hash = json_encode($hosts);
if (!isset($this->clients[$hash])) {
$options = [
'hosts' => [
$cluster
->getRawUrl(),
],
'options' => [],
'curl' => [
CURLOPT_CONNECTTIMEOUT => !empty($cluster->options['timeout']) ? $cluster->options['timeout'] : Cluster::ELASTICSEARCH_CONNECTOR_DEFAULT_TIMEOUT,
],
];
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, $cluster);
$this->clients[$hash] = $this->clientManagerFactory
->create($options);
}
return $this->clients[$hash];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ClientManager:: |
protected | property | Client manager factory. | |
ClientManager:: |
protected | property | Array of clients keyed by JSON encoded cluster URL and options. | |
ClientManager:: |
protected | property | Module handler service. | |
ClientManager:: |
public | function |
Get a client to interact with the given Elasticsearch cluster. Overrides ClientManagerInterface:: |
|
ClientManager:: |
public | function |
Create a client manager. Overrides ClientManagerInterface:: |