|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Maztech\HttpClients; |
|
4
|
|
|
|
|
5
|
|
|
use Maztech\Http\GraphRawResponse; |
|
6
|
|
|
use Maztech\Exceptions\InstagramSDKException; |
|
7
|
|
|
|
|
8
|
|
|
use GuzzleHttp\Client; |
|
9
|
|
|
use GuzzleHttp\Message\ResponseInterface; |
|
10
|
|
|
use GuzzleHttp\Ring\Exception\RingException; |
|
11
|
|
|
use GuzzleHttp\Exception\RequestException; |
|
12
|
|
|
|
|
13
|
|
|
class InstagramGuzzleHttpClient implements InstagramHttpClientInterface |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var \GuzzleHttp\Client The Guzzle client. |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $guzzleClient; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param \GuzzleHttp\Client|null The Guzzle client. |
|
|
|
|
|
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct(Client $guzzleClient = null) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->guzzleClient = $guzzleClient ?: new Client(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @inheritdoc |
|
30
|
|
|
*/ |
|
31
|
|
|
public function send($url, $method, $body, array $headers, $timeOut) |
|
32
|
|
|
{ |
|
33
|
|
|
$options = [ |
|
34
|
|
|
'headers' => $headers, |
|
35
|
|
|
'body' => $body, |
|
36
|
|
|
'timeout' => $timeOut, |
|
37
|
|
|
'connect_timeout' => 10, |
|
38
|
|
|
'verify' => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', |
|
39
|
|
|
]; |
|
40
|
|
|
$request = $this->guzzleClient->createRequest($method, $url, $options); |
|
41
|
|
|
|
|
42
|
|
|
try { |
|
43
|
|
|
$rawResponse = $this->guzzleClient->send($request); |
|
44
|
|
|
} catch (RequestException $e) { |
|
45
|
|
|
$rawResponse = $e->getResponse(); |
|
46
|
|
|
|
|
47
|
|
|
if ($e->getPrevious() instanceof RingException || !$rawResponse instanceof ResponseInterface) { |
|
48
|
|
|
throw new InstagramSDKException($e->getMessage(), $e->getCode()); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$rawHeaders = $this->getHeadersAsString($rawResponse); |
|
53
|
|
|
$rawBody = $rawResponse->getBody(); |
|
54
|
|
|
$httpStatusCode = $rawResponse->getStatusCode(); |
|
55
|
|
|
|
|
56
|
|
|
return new GraphRawResponse($rawHeaders, $rawBody, $httpStatusCode); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns the Guzzle array of headers as a string. |
|
61
|
|
|
* |
|
62
|
|
|
* @param ResponseInterface $response The Guzzle response. |
|
63
|
|
|
* |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getHeadersAsString(ResponseInterface $response) |
|
67
|
|
|
{ |
|
68
|
|
|
$headers = $response->getHeaders(); |
|
69
|
|
|
$rawHeaders = []; |
|
70
|
|
|
foreach ($headers as $name => $values) { |
|
71
|
|
|
$rawHeaders[] = $name . ": " . implode(", ", $values); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return implode("\r\n", $rawHeaders); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
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