| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\HttpClient; |
| 13 |
|
| 14 |
use Symfony\Contracts\HttpClient\HttpClientInterface; |
| 15 |
use Symfony\Contracts\HttpClient\ResponseInterface; |
| 16 |
use Symfony\Contracts\HttpClient\ResponseStreamInterface; |
| 17 |
use Symfony\Contracts\Service\ResetInterface; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
trait DecoratorTrait |
| 25 |
{ |
| 26 |
private HttpClientInterface $client; |
| 27 |
|
| 28 |
public function __construct(?HttpClientInterface $client = null) |
| 29 |
{ |
| 30 |
$this->client = $client ?? HttpClient::create(); |
| 31 |
} |
| 32 |
|
| 33 |
public function request(string $method, string $url, array $options = []): ResponseInterface |
| 34 |
{ |
| 35 |
return $this->client->request($method, $url, $options); |
| 36 |
} |
| 37 |
|
| 38 |
public function stream(ResponseInterface|iterable $responses, ?float $timeout = null): ResponseStreamInterface |
| 39 |
{ |
| 40 |
return $this->client->stream($responses, $timeout); |
| 41 |
} |
| 42 |
|
| 43 |
public function withOptions(array $options): static |
| 44 |
{ |
| 45 |
$clone = clone $this; |
| 46 |
$clone->client = $this->client->withOptions($options); |
| 47 |
|
| 48 |
return $clone; |
| 49 |
} |
| 50 |
|
| 51 |
public function reset(): void |
| 52 |
{ |
| 53 |
if ($this->client instanceof ResetInterface) { |
| 54 |
$this->client->reset(); |
| 55 |
} |
| 56 |
} |
| 57 |
} |