1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* It's free open-source software released under the MIT License. |
5
|
|
|
* |
6
|
|
|
* @author Anatoly Nekhay <[email protected]> |
7
|
|
|
* @copyright Copyright (c) 2018, Anatoly Nekhay |
8
|
|
|
* @license https://github.com/sunrise-php/http-client-curl/blob/master/LICENSE |
9
|
|
|
* @link https://github.com/sunrise-php/http-client-curl |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sunrise\Http\Client\Curl; |
15
|
|
|
|
16
|
|
|
use InvalidArgumentException; |
17
|
|
|
use LogicException; |
18
|
|
|
use Psr\Http\Message\MessageInterface; |
19
|
|
|
use Psr\Http\Message\RequestInterface; |
20
|
|
|
use Psr\Http\Message\StreamInterface; |
21
|
|
|
use Psr\Http\Message\UriInterface; |
22
|
|
|
|
23
|
|
|
use function current; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @since 2.0.0 |
27
|
|
|
*/ |
28
|
|
|
final class MultiRequest implements RequestInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var non-empty-array<array-key, RequestInterface> |
|
|
|
|
32
|
|
|
*/ |
33
|
|
|
private array $requests; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @throws InvalidArgumentException |
37
|
|
|
*/ |
38
|
1 |
|
public function __construct(RequestInterface ...$requests) |
39
|
|
|
{ |
40
|
1 |
|
if ($requests === []) { |
41
|
|
|
throw new InvalidArgumentException('At least one request is expected.'); |
42
|
|
|
} |
43
|
|
|
|
44
|
1 |
|
$this->requests = $requests; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return non-empty-array<array-key, RequestInterface> |
|
|
|
|
49
|
|
|
*/ |
50
|
1 |
|
public function getRequests(): array |
51
|
|
|
{ |
52
|
1 |
|
return $this->requests; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getProtocolVersion(): string |
56
|
|
|
{ |
57
|
|
|
return current($this->requests)->getProtocolVersion(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function withProtocolVersion($version): static |
61
|
|
|
{ |
62
|
|
|
throw new LogicException('Not implemented.'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getHeaders(): array |
66
|
|
|
{ |
67
|
|
|
return current($this->requests)->getHeaders(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function hasHeader($name): bool |
71
|
|
|
{ |
72
|
|
|
return current($this->requests)->hasHeader($name); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getHeader($name): array |
76
|
|
|
{ |
77
|
|
|
return current($this->requests)->getHeader($name); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getHeaderLine($name): string |
81
|
|
|
{ |
82
|
|
|
return current($this->requests)->getHeaderLine($name); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function withHeader($name, $value): MessageInterface |
86
|
|
|
{ |
87
|
|
|
throw new LogicException('Not implemented.'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function withAddedHeader($name, $value): MessageInterface |
91
|
|
|
{ |
92
|
|
|
throw new LogicException('Not implemented.'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function withoutHeader($name): MessageInterface |
96
|
|
|
{ |
97
|
|
|
throw new LogicException('Not implemented.'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getBody(): StreamInterface |
101
|
|
|
{ |
102
|
|
|
return current($this->requests)->getBody(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function withBody(StreamInterface $body): MessageInterface |
106
|
|
|
{ |
107
|
|
|
throw new LogicException('Not implemented.'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function getRequestTarget(): string |
111
|
|
|
{ |
112
|
|
|
return current($this->requests)->getRequestTarget(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function withRequestTarget($requestTarget): RequestInterface |
116
|
|
|
{ |
117
|
|
|
throw new LogicException('Not implemented.'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function getMethod(): string |
121
|
|
|
{ |
122
|
|
|
return current($this->requests)->getMethod(); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function withMethod($method): RequestInterface |
126
|
|
|
{ |
127
|
|
|
throw new LogicException('Not implemented.'); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function getUri(): UriInterface |
131
|
|
|
{ |
132
|
|
|
return current($this->requests)->getUri(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface |
136
|
|
|
{ |
137
|
|
|
throw new LogicException('Not implemented.'); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|