getHeaders() as $name => $value) { $headers[] = $name . ': ' . $value; } $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $request->getUrl(), CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $headers, CURLOPT_TIMEOUT => $request->getTimeout(), CURLOPT_CONNECTTIMEOUT => 10, ]); match ($request->getMethod()) { 'GET' => curl_setopt($ch, CURLOPT_HTTPGET, true), 'POST' => curl_setopt($ch, CURLOPT_POST, true), default => curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request->getMethod()), }; if ($request->getBody() !== null) { curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getBody()); } $body = curl_exec($ch); if ($body === false) { $error = curl_error($ch); curl_close($ch); throw new RuntimeException('Curl error: ' . $error); } $status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return new Response($status, $body); } }