1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ArangoClient\Http; |
6
|
|
|
|
7
|
|
|
use Spatie\DataTransferObject\DataTransferObject; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class HttpClientConfig |
11
|
|
|
* |
12
|
|
|
* @SuppressWarnings(PHPMD.CamelCasePropertyName) |
13
|
|
|
* (Guzzle uses snake_case for its configuration options) |
14
|
|
|
*/ |
15
|
|
|
class HttpClientConfig extends DataTransferObject |
16
|
|
|
{ |
17
|
|
|
public string $endpoint = 'http://localhost:8529'; |
18
|
|
|
|
19
|
|
|
public ?string $host = null; |
20
|
|
|
|
21
|
|
|
public string|int|null $port = null; |
22
|
|
|
|
23
|
|
|
public int|float $version = 1.1; |
24
|
|
|
|
25
|
|
|
public string $connection = 'Keep-Alive'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array<mixed>|false |
29
|
|
|
*/ |
30
|
|
|
public $allow_redirects = false; |
31
|
|
|
|
32
|
|
|
public float $connect_timeout = 0; |
33
|
|
|
|
34
|
|
|
public ?string $username = null; |
35
|
|
|
|
36
|
|
|
public ?string $password = null; |
37
|
|
|
|
38
|
|
|
public string $database = '_system'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Small responses are decoded with json_decode. This is fast but memory intensive. |
42
|
|
|
* Large responses are decoded with Halaxa/json-machine stream decoder. |
43
|
|
|
* $jsonStreamDecoderThreshold is the response length cutoff in bytes which determines which decoder is used. |
44
|
|
|
* |
45
|
|
|
* @var int |
46
|
|
|
*/ |
47
|
|
|
public int $jsonStreamDecoderThreshold = 1 * 1024 * 1024; // Default 1 MB |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return array<array<mixed>|string|numeric|bool|null> |
51
|
|
|
*/ |
52
|
|
|
public function mapGuzzleHttpClientConfig(): array |
53
|
|
|
{ |
54
|
|
|
return ['base_uri' => $this->endpoint, 'version' => $this->version, 'allow_redirects' => $this->allow_redirects, 'connect_timeout' => $this->connect_timeout, 'auth' => [ |
55
|
|
|
$this->username, |
56
|
|
|
$this->password, |
57
|
|
|
], 'headers' => [ |
58
|
|
|
'Connection' => $this->connection, |
59
|
|
|
]]; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|