requestFactory->createRequest($method, $baseUri . $url); $body = $options['body'] ?? null; if ($body !== null) { $request = $request->withBody($this->streamFactory->createStream($body)); } foreach ($this->options as $name => $value) { $request = $request->withHeader($name, $value); } foreach ($options['headers'] ?? [] as $name => $value) { $request = $request->withHeader($name, $value); } $response = $this->client->sendRequest($request); return static::fromPsr17($response); } /** * @param ResponseInterface|iterable $responses */ public function stream(iterable|ResponseInterface $responses, float $timeout = null): ResponseStreamInterface { throw new LogicException('Not implemented'); } public function withOptions(array $options): static { $this->options = $options; return $this; } protected static function fromPsr17(Psr17ResponseInterface $response): ResponseInterface { $headers = $response->getHeaders(); $content = $response->getBody() ->getContents(); $status = $response->getStatusCode(); return new class($status, $headers, $content) implements ResponseInterface { /** * @param array $headers */ public function __construct( private readonly int $status, private readonly array $headers, private readonly string $content, ) { } public function getStatusCode(): int { return $this->status; } /** * @return array */ public function getHeaders(bool $throw = true): array { return $this->headers; } public function getContent(bool $throw = true): string { return $this->content; } /** * @return array */ public function toArray(bool $throw = true): array { $result = json_decode($this->content, true); if (! is_array($result) || json_last_error() !== JSON_ERROR_NONE) { throw new JsonException('Failed to decode JSON response: ' . json_last_error_msg()); } return $result; } public function cancel(): void { // noop } public function getInfo(string $type = null): mixed { return null; } }; } }