|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Oliverde8\Component\PhpEtl\Item; |
|
4
|
|
|
|
|
5
|
|
|
use oliverde8\AssociativeArraySimplified\AssociativeArray; |
|
6
|
|
|
use Symfony\Component\HttpClient\Exception\TimeoutException; |
|
|
|
|
|
|
7
|
|
|
use Symfony\Component\HttpClient\Response\AsyncResponse; |
|
|
|
|
|
|
8
|
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface; |
|
|
|
|
|
|
9
|
|
|
use Symfony\Contracts\HttpClient\ResponseInterface; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class AsyncHttpClientResponseItem implements AsyncItemInterface |
|
12
|
|
|
{ |
|
13
|
|
|
private HttpClientInterface $client; |
|
14
|
|
|
|
|
15
|
|
|
private ResponseInterface $response; |
|
16
|
|
|
|
|
17
|
|
|
private bool $responseIsJson; |
|
18
|
|
|
|
|
19
|
|
|
private ?string $responseKey; |
|
20
|
|
|
|
|
21
|
|
|
private array $baseData; |
|
22
|
|
|
|
|
23
|
|
|
private bool $isRunning = true; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param ResponseInterface $response |
|
27
|
|
|
* @param bool $responseIsJson |
|
28
|
|
|
* @param string|null $responseKey |
|
29
|
|
|
* @param array $baseData |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct( |
|
32
|
|
|
HttpClientInterface $client, |
|
33
|
|
|
ResponseInterface $response, |
|
34
|
|
|
bool $responseIsJson, |
|
35
|
|
|
?string $responseKey, |
|
36
|
|
|
array $baseData |
|
37
|
|
|
) { |
|
38
|
|
|
$this->client = $client; |
|
39
|
|
|
$this->response = $response; |
|
40
|
|
|
$this->responseIsJson = $responseIsJson; |
|
41
|
|
|
$this->responseKey = $responseKey; |
|
42
|
|
|
$this->baseData = $baseData; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
public function isRunning(): bool |
|
47
|
|
|
{ |
|
48
|
|
|
try { |
|
49
|
|
|
foreach ($this->client->stream($this->response, 0.01) as $chunk) { |
|
50
|
|
|
if ($chunk->isLast()) { |
|
51
|
|
|
return false; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
|
|
|
|
|
54
|
|
|
} catch (TimeoutException $exception) { |
|
55
|
|
|
// This is normal, we have used a very low stream timeout because we wish to continue processing |
|
56
|
|
|
// other items while this item is being downloaded. |
|
57
|
|
|
return true; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function getItem(): ItemInterface |
|
62
|
|
|
{ |
|
63
|
|
|
$responseData = [ |
|
64
|
|
|
'content' => $this->response->getContent(), |
|
65
|
|
|
'headers' => $this->response->getHeaders(), |
|
66
|
|
|
'status_code' => $this->response->getStatusCode(), |
|
67
|
|
|
]; |
|
68
|
|
|
if ($this->responseIsJson) { |
|
69
|
|
|
$responseData['content'] = $this->response->toArray(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$data = $this->baseData; |
|
73
|
|
|
if ($this->responseKey) { |
|
74
|
|
|
AssociativeArray::setFromKey($data, $this->responseKey, $responseData); |
|
75
|
|
|
} else { |
|
76
|
|
|
$data = $responseData; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return new DataItem($data); |
|
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