1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Oliverde8\Component\PhpEtl\ChainOperation\Transformer; |
6
|
|
|
|
7
|
|
|
use oliverde8\AssociativeArraySimplified\AssociativeArray; |
8
|
|
|
use Oliverde8\Component\PhpEtl\ChainOperation\AbstractChainOperation; |
9
|
|
|
use Oliverde8\Component\PhpEtl\ChainOperation\DataChainOperationInterface; |
10
|
|
|
use Oliverde8\Component\PhpEtl\Item\AsyncHttpClientResponseItem; |
11
|
|
|
use Oliverde8\Component\PhpEtl\Item\DataItem; |
12
|
|
|
use Oliverde8\Component\PhpEtl\Item\DataItemInterface; |
13
|
|
|
use Oliverde8\Component\PhpEtl\Item\ItemInterface; |
14
|
|
|
use Oliverde8\Component\PhpEtl\Model\ExecutionContext; |
15
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionLanguage; |
16
|
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface; |
|
|
|
|
17
|
|
|
|
18
|
|
|
class SimpleHttpOperation extends AbstractChainOperation implements DataChainOperationInterface |
19
|
|
|
{ |
20
|
|
|
private HttpClientInterface $client; |
21
|
|
|
|
22
|
|
|
private string $method = "GET"; |
23
|
|
|
private string $url; |
24
|
|
|
|
25
|
|
|
private bool $responseIsJson; |
26
|
|
|
|
27
|
|
|
private ?string $optionsKey; |
28
|
|
|
|
29
|
|
|
protected ?string $responseKey; |
30
|
|
|
|
31
|
|
|
private ExpressionLanguage $expressionLanguage; |
32
|
|
|
|
33
|
|
|
public function __construct( |
34
|
|
|
HttpClientInterface $client, |
35
|
|
|
string $method, |
36
|
|
|
string $url, |
37
|
|
|
bool $responseIsJson, |
38
|
|
|
?string $optionsKey, |
39
|
|
|
?string $responseKey |
40
|
|
|
) { |
41
|
|
|
$this->client = $client; |
42
|
|
|
$this->method = $method; |
43
|
|
|
$this->url = $url; |
44
|
|
|
$this->responseIsJson = $responseIsJson; |
45
|
|
|
$this->optionsKey = $optionsKey; |
46
|
|
|
$this->responseKey = $responseKey; |
47
|
|
|
|
48
|
|
|
$this->expressionLanguage = new ExpressionLanguage(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
public function processData(DataItemInterface $item, ExecutionContext $context): ItemInterface |
53
|
|
|
{ |
54
|
|
|
$data = $item->getData(); |
55
|
|
|
if ($this->optionsKey) { |
56
|
|
|
$options = AssociativeArray::getFromKey($data, $this->optionsKey, []); |
57
|
|
|
} else { |
58
|
|
|
$options = $data; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$url = $this->url; |
62
|
|
|
if (strpos($url, "@") === 0) { |
63
|
|
|
$url = ltrim($url, '@'); |
64
|
|
|
$url = $this->expressionLanguage->evaluate($url, ['data' => $data]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$response = $this->client->request($this->method, $url, $options); |
68
|
|
|
$response->getInfo(); |
69
|
|
|
|
70
|
|
|
return new AsyncHttpClientResponseItem($this->client, $response, $this->responseIsJson, $this->responseKey, $data); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
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