|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bokbasen\ApiClient; |
|
4
|
|
|
|
|
5
|
|
|
use Bokbasen\ApiClient\Exceptions\BokbasenApiClientException; |
|
6
|
|
|
use Http\Client\HttpClient; |
|
7
|
|
|
use Http\Discovery\Psr17FactoryDiscovery; |
|
8
|
|
|
use Http\Discovery\Psr18ClientDiscovery; |
|
9
|
|
|
use Http\Message\StreamFactory; |
|
10
|
|
|
use Psr\Http\Client\ClientExceptionInterface; |
|
11
|
|
|
use Psr\Http\Client\ClientInterface; |
|
12
|
|
|
use Psr\Http\Message\RequestFactoryInterface; |
|
|
|
|
|
|
13
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
14
|
|
|
use Psr\Http\Message\StreamInterface; |
|
15
|
|
|
use Psr\Http\Message\UriInterface; |
|
16
|
|
|
|
|
17
|
|
|
class Caller |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var HttpClient |
|
21
|
|
|
*/ |
|
22
|
|
|
private $httpClient; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var StreamFactory |
|
26
|
|
|
*/ |
|
27
|
|
|
private $streamFactory; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var RequestFactoryInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
private $requestFactory; |
|
33
|
|
|
|
|
34
|
2 |
|
public function __construct( |
|
35
|
|
|
ClientInterface $httpClient = null, |
|
36
|
|
|
RequestFactoryInterface $requestFactory = null, |
|
37
|
|
|
StreamInterface $streamFactory = null |
|
38
|
|
|
) { |
|
39
|
2 |
|
$this->httpClient = $httpClient ?: Psr18ClientDiscovery::find(); |
|
|
|
|
|
|
40
|
|
|
$this->requestFactory = $requestFactory ?: Psr17FactoryDiscovery::findRequestFactory(); |
|
41
|
|
|
$this->streamFactory = $streamFactory ?: Psr17FactoryDiscovery::findStreamFactory(); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param string $method |
|
46
|
|
|
* @param string|UriInterface $url |
|
47
|
|
|
* @param array $headers |
|
48
|
|
|
* @param resource|string|StreamInterface|null $body |
|
49
|
|
|
* |
|
50
|
|
|
* @return ResponseInterface |
|
51
|
|
|
* |
|
52
|
|
|
* @throws BokbasenApiClientException |
|
53
|
|
|
*/ |
|
54
|
|
|
public function request(string $method, $url, array $headers = [], $body = null): ResponseInterface |
|
55
|
|
|
{ |
|
56
|
|
|
try { |
|
57
|
|
|
$request = $this->requestFactory->createRequest($method, $url); |
|
58
|
|
|
|
|
59
|
|
|
if (!empty($headers)) { |
|
60
|
|
|
foreach ($headers as $name => $value) { |
|
61
|
|
|
$request = $request->withHeader($name, $value); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if ($body !== null) { |
|
66
|
|
|
$request = $request->withBody( |
|
67
|
|
|
$this->streamFactory->createStream($body) |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $this->httpClient->sendRequest($request); |
|
72
|
|
|
} catch (ClientExceptionInterface | \Exception $e) { |
|
73
|
|
|
throw new BokbasenApiClientException($e->getMessage(), $e->getCode(), $e); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function setHttpClient(ClientInterface $httpClient): void |
|
78
|
|
|
{ |
|
79
|
|
|
$this->httpClient = $httpClient; |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths