Skip to content

Commit 4aa99c4

Browse files
authored
Merge pull request #43 from ensi-platform/ecs-365
ECS-365 elastic custom http client
2 parents 25b8e5e + a3f1714 commit 4aa99c4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

config/config.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
'username' => env('ELASTICSEARCH_USERNAME', ''),
1212
'password' => env('ELASTICSEARCH_PASSWORD', ''),
1313
'ssl_verification' => env('ELASTICSEARCH_SSL_VERIFICATION', false),
14-
'handler' => null, // for call_user_func_array
14+
15+
'http_client' => null, // class implementing the \Psr\Http\Client\ClientInterface
16+
'http_client_options' => null, // for call_user_func_array
1517
],
1618
];

src/ElasticClient.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,16 @@ public static function fromConfig(array $config): static
157157
$builder->setBasicAuthentication($username, $password);
158158
}
159159

160-
if (filled($config['handler'] ?? null)) {
161-
$builder->setHandler(call_user_func_array($config['handler'], []));
160+
if (filled($config['http_client'] ?? null)) {
161+
$client = new $config['http_client']();
162+
163+
$builder->setHttpClient($client);
164+
}
165+
166+
if (filled($config['http_client_options'] ?? null)) {
167+
$options = call_user_func_array($config['http_client_options'], []);
168+
169+
$builder->setHttpClientOptions($options);
162170
}
163171

164172
return new static($builder->build());

0 commit comments

Comments
 (0)