forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpClientFactory.php
More file actions
43 lines (35 loc) · 829 Bytes
/
Copy pathHttpClientFactory.php
File metadata and controls
43 lines (35 loc) · 829 Bytes
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
<?php declare(strict_types = 1);
namespace PHPStan\Internal;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use PHPStan\DependencyInjection\AutowiredService;
use function extension_loaded;
#[AutowiredService]
final class HttpClientFactory
{
public function __construct(
private int $timeout = 30,
private int $connectTimeout = 10,
)
{
}
/**
* @param array<mixed> $config
*
* @see \GuzzleHttp\RequestOptions
*/
public function createClient(array $config): Client
{
if (
!isset($config['headers']['Accept-Encoding'])
&& extension_loaded('zlib')
) {
$config['headers']['Accept-Encoding'] = 'gzip,deflate';
}
$defaults = [
RequestOptions::TIMEOUT => $this->timeout,
RequestOptions::CONNECT_TIMEOUT => $this->connectTimeout,
];
return new Client($config + $defaults);
}
}