1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace InShore\Bookwhen\ValueObjects\Transporter; |
6
|
|
|
|
7
|
|
|
use Http\Discovery\Psr17Factory; |
8
|
|
|
use Http\Message\MultipartStream\MultipartStreamBuilder; |
|
|
|
|
9
|
|
|
use InShore\Bookwhen\Contracts\Request; |
|
|
|
|
10
|
|
|
use InShore\Bookwhen\Enums\Transporter\ContentType; |
|
|
|
|
11
|
|
|
use InShore\Bookwhen\Enums\Transporter\Method; |
12
|
|
|
use InShore\Bookwhen\ValueObjects\ResourceUri; |
13
|
|
|
use Psr\Http\Message\RequestInterface; |
14
|
|
|
use Psr\Http\Message\StreamInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @internal |
18
|
|
|
*/ |
19
|
|
|
final class Payload |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Creates a new Request value object. |
23
|
|
|
* |
24
|
|
|
* @param array<string, mixed> $parameters |
25
|
|
|
*/ |
26
|
11 |
|
private function __construct( |
27
|
|
|
//private readonly ContentType $contentType, |
28
|
|
|
private readonly Method $method, |
29
|
|
|
private readonly ResourceUri $uri, |
30
|
|
|
private readonly array $parameters = [], |
31
|
|
|
) { |
32
|
|
|
// .. |
33
|
11 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Creates a new Payload value object from the given parameters. |
37
|
|
|
*/ |
38
|
5 |
|
public static function list(string $resource, array $parameters = []): self |
39
|
|
|
{ |
40
|
|
|
//var_export($parameters); |
41
|
|
|
//$contentType = ContentType::JSON; |
42
|
5 |
|
$method = Method::GET; |
43
|
5 |
|
$uri = ResourceUri::list($resource); |
44
|
|
|
|
45
|
5 |
|
return new self($method, $uri, $parameters); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Creates a new Payload value object from the given parameters. |
50
|
|
|
*/ |
51
|
6 |
|
public static function retrieve(string $resource, string $id, array $parameters = []): self |
52
|
|
|
{ |
53
|
|
|
// $contentType = ContentType::JSON; |
54
|
6 |
|
$method = Method::GET; |
55
|
6 |
|
$uri = ResourceUri::retrieve($resource, $id); |
56
|
|
|
|
57
|
6 |
|
return new self($method, $uri, $parameters); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Creates a new Psr 7 Request instance. |
62
|
|
|
*/ |
63
|
11 |
|
public function toRequest(BaseUri $baseUri, Headers $headers, QueryParams $queryParams): RequestInterface |
|
|
|
|
64
|
|
|
{ |
65
|
11 |
|
$psr17Factory = new Psr17Factory(); |
66
|
|
|
|
67
|
11 |
|
$uri = $baseUri->toString() . $this->uri->toString(); |
68
|
|
|
|
69
|
11 |
|
if (!empty($this->parameters)) { |
70
|
6 |
|
$uri .= '?' . http_build_query($this->parameters); |
71
|
|
|
} |
72
|
|
|
|
73
|
11 |
|
$request = $psr17Factory->createRequest($this->method->value, $uri); |
74
|
|
|
|
75
|
11 |
|
foreach ($headers->toArray() as $name => $value) { |
76
|
11 |
|
$request = $request->withHeader($name, $value); |
77
|
|
|
} |
78
|
11 |
|
return $request; |
|
|
|
|
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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