| Total Complexity | 4 |
| Total Lines | 68 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class ElasticsearchClients |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var array |
||
| 11 | */ |
||
| 12 | private $elasticsearchClients = []; |
||
| 13 | |||
| 14 | /** @var ClientBuilder */ |
||
| 15 | private $clientBuilder; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * ElasticsearchClients constructor. |
||
| 19 | */ |
||
| 20 | 63 | public function __construct() |
|
| 23 | 63 | } |
|
| 24 | |||
| 25 | /** |
||
| 26 | * Add |
||
| 27 | * |
||
| 28 | * @param string $esClientKey |
||
| 29 | * @param string $host |
||
| 30 | * @param int $port |
||
| 31 | * @param string $scheme |
||
| 32 | * @param null|string $user |
||
| 33 | * @param null|string $password |
||
| 34 | * @param int $retries |
||
| 35 | */ |
||
| 36 | 63 | public function add( |
|
| 37 | string $esClientKey, |
||
| 38 | string $host, |
||
| 39 | int $port, |
||
| 40 | string $scheme, |
||
| 41 | ?string $user = null, |
||
| 42 | ?string $password = null, |
||
| 43 | int $retries = 1 |
||
| 44 | ) { |
||
| 45 | 63 | $this->elasticsearchClients[$esClientKey] = $this->clientBuilder->setHosts([ |
|
| 46 | [ |
||
| 47 | 63 | 'host' => $host, |
|
| 48 | 63 | 'port' => $port, |
|
| 49 | 63 | 'scheme' => $scheme, |
|
| 50 | 63 | 'user' => $user, |
|
| 51 | 63 | 'pass' => $password |
|
| 52 | ] |
||
| 53 | 63 | ])->setRetries($retries)->build(); |
|
| 54 | 63 | } |
|
| 55 | |||
| 56 | /** |
||
| 57 | * Get |
||
| 58 | * |
||
| 59 | * @param string $esClientKey |
||
| 60 | * @return Client|null |
||
| 61 | */ |
||
| 62 | 47 | public function get(string $esClientKey) : ?Client |
|
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * All |
||
| 69 | * |
||
| 70 | * @return Client[] |
||
| 71 | */ |
||
| 72 | 6 | public function all() : array |
|
| 77 |