1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maztech\HttpClients; |
4
|
|
|
|
5
|
|
|
use Maztech\Http\GraphRawResponse; |
6
|
|
|
use Maztech\Exceptions\InstagramSDKException; |
7
|
|
|
|
8
|
|
|
class InstagramStreamHttpClient implements InstagramHttpClientInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var InstagramStream Procedural stream wrapper as object. |
12
|
|
|
*/ |
13
|
|
|
protected $InstagramStream; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @param InstagramStream|null Procedural stream wrapper as object. |
|
|
|
|
17
|
|
|
*/ |
18
|
|
|
public function __construct(InstagramStream $InstagramStream = null) |
19
|
|
|
{ |
20
|
|
|
$this->InstagramStream = $InstagramStream ?: new InstagramStream(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @inheritdoc |
25
|
|
|
*/ |
26
|
|
|
public function send($url, $method, $body, array $headers, $timeOut) |
27
|
|
|
{ |
28
|
|
|
$options = [ |
29
|
|
|
'http' => [ |
30
|
|
|
'method' => $method, |
31
|
|
|
'header' => $this->compileHeader($headers), |
32
|
|
|
'content' => $body, |
33
|
|
|
'timeout' => $timeOut, |
34
|
|
|
'ignore_errors' => true |
35
|
|
|
], |
36
|
|
|
'ssl' => [ |
37
|
|
|
'verify_peer' => true, |
38
|
|
|
'verify_peer_name' => true, |
39
|
|
|
'allow_self_signed' => true, // All root certificates are self-signed |
40
|
|
|
'cafile' => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', |
41
|
|
|
], |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
$this->InstagramStream->streamContextCreate($options); |
45
|
|
|
$rawBody = $this->InstagramStream->fileGetContents($url); |
46
|
|
|
$rawHeaders = $this->InstagramStream->getResponseHeaders(); |
47
|
|
|
|
48
|
|
|
if ($rawBody === false || empty($rawHeaders)) { |
49
|
|
|
throw new InstagramSDKException('Stream returned an empty response', 660); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$rawHeaders = implode("\r\n", $rawHeaders); |
53
|
|
|
|
54
|
|
|
return new GraphRawResponse($rawHeaders, $rawBody); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Formats the headers for use in the stream wrapper. |
59
|
|
|
* |
60
|
|
|
* @param array $headers The request headers. |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
|
|
public function compileHeader(array $headers) |
65
|
|
|
{ |
66
|
|
|
$header = []; |
67
|
|
|
foreach ($headers as $k => $v) { |
68
|
|
|
$header[] = $k . ': ' . $v; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return implode("\r\n", $header); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
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