1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bokbasen\ApiClient; |
4
|
|
|
|
5
|
|
|
use Bokbasen\ApiClient\Exceptions\BokbasenApiClientException; |
6
|
|
|
use Http\Client\HttpClient; |
7
|
|
|
use Http\Discovery\HttpClientDiscovery; |
8
|
|
|
use Http\Discovery\MessageFactoryDiscovery; |
9
|
|
|
use Http\Discovery\Psr17FactoryDiscovery; |
10
|
|
|
use Http\Discovery\Psr18ClientDiscovery; |
11
|
|
|
use Http\Discovery\StreamFactoryDiscovery; |
12
|
|
|
use Http\Message\MessageFactory; |
13
|
|
|
use Http\Message\StreamFactory; |
14
|
|
|
use Psr\Http\Client\ClientExceptionInterface; |
15
|
|
|
use Psr\Http\Client\ClientInterface; |
16
|
|
|
use Psr\Http\Message\RequestFactoryInterface; |
|
|
|
|
17
|
|
|
use Psr\Http\Message\ResponseInterface; |
18
|
|
|
use Psr\Http\Message\StreamInterface; |
19
|
|
|
use Psr\Http\Message\UriInterface; |
20
|
|
|
|
21
|
|
|
class Caller |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var HttpClient |
25
|
|
|
*/ |
26
|
|
|
private $httpClient; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var StreamFactory |
30
|
|
|
*/ |
31
|
|
|
private $streamFactory; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var RequestFactoryInterface |
35
|
|
|
*/ |
36
|
|
|
private $requestFactory; |
37
|
|
|
|
38
|
2 |
|
public function __construct( |
39
|
|
|
ClientInterface $httpClient = null, |
40
|
|
|
RequestFactoryInterface $requestFactory = null, |
41
|
|
|
StreamInterface $streamFactory = null |
42
|
|
|
) { |
43
|
2 |
|
$this->httpClient = $httpClient ?: Psr18ClientDiscovery::find(); |
|
|
|
|
44
|
|
|
$this->requestFactory = $requestFactory ?: Psr17FactoryDiscovery::findRequestFactory(); |
45
|
|
|
$this->streamFactory = $streamFactory ?: Psr17FactoryDiscovery::findStreamFactory(); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $method |
50
|
|
|
* @param string|UriInterface $url |
51
|
|
|
* @param array $headers |
52
|
|
|
* @param resource|string|StreamInterface|null $body |
53
|
|
|
* |
54
|
|
|
* @return ResponseInterface |
55
|
|
|
* |
56
|
|
|
* @throws BokbasenApiClientException |
57
|
|
|
*/ |
58
|
|
|
public function request(string $method, $url, array $headers = [], $body = null): ResponseInterface |
59
|
|
|
{ |
60
|
|
|
try { |
61
|
|
|
$request = $this->requestFactory->createRequest($method, $url); |
62
|
|
|
|
63
|
|
|
if (!empty($headers)) { |
64
|
|
|
foreach ($headers as $name => $value) { |
65
|
|
|
$request = $request->withHeader($name, $value); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if ($body !== null) { |
70
|
|
|
$request = $request->withBody( |
71
|
|
|
$this->streamFactory->createStream($body) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $this->httpClient->sendRequest($request); |
76
|
|
|
} catch (ClientExceptionInterface | \Exception $e) { |
77
|
|
|
throw new BokbasenApiClientException($e->getMessage(), $e->getCode(), $e); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function setHttpClient(ClientInterface $httpClient): void |
82
|
|
|
{ |
83
|
|
|
$this->httpClient = $httpClient; |
|
|
|
|
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
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