chore: lots of changes

This commit is contained in:
2025-05-24 07:09:22 +02:00
parent 77ee769d5e
commit 899227b0a4
178 changed files with 5145 additions and 53 deletions

View File

@@ -0,0 +1,49 @@
<?php
namespace App\Framework\HttpClient;
use App\Framework\Http\Headers;
use App\Framework\Http\Status;
final readonly class CurlHttpClient implements HttpClient
{
public function send(ClientRequest $request): ClientResponse
{
$ch = curl_init();
$options = [
CURLOPT_URL => $request->url,
CURLOPT_CUSTOMREQUEST => $request->method->value,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
];
if ($request->body !== '') {
$options[CURLOPT_POSTFIELDS] = $request->body;
}
if (count($request->headers->all()) > 0) {
$options[CURLOPT_HTTPHEADER] = $request->headers->all();
}
curl_setopt_array($ch, $options);
$raw = curl_exec($ch);
if ($raw === false) {
throw new HttpException(curl_error($ch), curl_errno($ch));
}
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headersRaw = substr($raw, 0, $headerSize);
$body = substr($raw, $headerSize);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
#$headers = Headers::fromString($headersRaw);
$headers = new Headers();
return new ClientResponse(Status::from($status), $headers, $body);
}
}