-
Notifications
You must be signed in to change notification settings - Fork 972
Expand file tree
/
Copy pathGuzzle.php
More file actions
51 lines (46 loc) · 1.75 KB
/
Guzzle.php
File metadata and controls
51 lines (46 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Elasticsearch PHP Client
*
* @link https://github.com/elastic/elasticsearch-php
* @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co)
* @license https://opensource.org/licenses/MIT MIT License
*
* Licensed to Elasticsearch B.V under one or more agreements.
* Elasticsearch B.V licenses this file to you under the MIT License.
* See the LICENSE file in the project root for more information.
*/
declare(strict_types = 1);
namespace Elastic\Elasticsearch\Transport\Adapter;
use Elastic\Elasticsearch\Transport\RequestOptions;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions As GuzzleOptions;
use Psr\Http\Client\ClientInterface;
class Guzzle implements AdapterInterface
{
public function setConfig(ClientInterface $client, array $config, array $clientOptions): ClientInterface
{
$guzzleConfig = [];
foreach ($config as $key => $value) {
switch ($key) {
case RequestOptions::SSL_CERT:
$guzzleConfig[GuzzleOptions::CERT] = $value;
break;
case RequestOptions::SSL_KEY:
$guzzleConfig[GuzzleOptions::SSL_KEY] = $value;
break;
case RequestOptions::SSL_VERIFY:
$guzzleConfig[GuzzleOptions::VERIFY] = $value;
break;
case RequestOptions::SSL_CA:
$guzzleConfig[GuzzleOptions::VERIFY] = $value;
}
}
/** @var Client $client */
if(method_exists($client, 'getConfig')){
$clientOptions = array_merge($clientOptions, $client->getConfig());
}
$class = get_class($client);
return new $class(array_merge($clientOptions, $guzzleConfig));
}
}