| 1 |
<?php |
| 2 |
|
| 3 |
declare (strict_types=1); |
| 4 |
namespace WCPOS\Vendor\Sentry\Spotlight; |
| 5 |
|
| 6 |
use WCPOS\Vendor\Sentry\HttpClient\Request; |
| 7 |
use WCPOS\Vendor\Sentry\HttpClient\Response; |
| 8 |
/** |
| 9 |
* @internal |
| 10 |
*/ |
| 11 |
class SpotlightClient |
| 12 |
{ |
| 13 |
public static function sendRequest(Request $request, string $url) : Response |
| 14 |
{ |
| 15 |
if (!\extension_loaded('curl')) { |
| 16 |
throw new \RuntimeException('The cURL PHP extension must be enabled to use the SpotlightClient.'); |
| 17 |
} |
| 18 |
$requestData = $request->getStringBody(); |
| 19 |
if ($requestData === null) { |
| 20 |
throw new \RuntimeException('The request data is empty.'); |
| 21 |
} |
| 22 |
$curlHandle = \curl_init(); |
| 23 |
\curl_setopt($curlHandle, \CURLOPT_URL, $url); |
| 24 |
\curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, ['Content-Type: application/x-sentry-envelope']); |
| 25 |
\curl_setopt($curlHandle, \CURLOPT_TIMEOUT, 2.0); |
| 26 |
\curl_setopt($curlHandle, \CURLOPT_CONNECTTIMEOUT, 1.0); |
| 27 |
\curl_setopt($curlHandle, \CURLOPT_ENCODING, ''); |
| 28 |
\curl_setopt($curlHandle, \CURLOPT_POST, \true); |
| 29 |
\curl_setopt($curlHandle, \CURLOPT_POSTFIELDS, $requestData); |
| 30 |
\curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, \true); |
| 31 |
\curl_setopt($curlHandle, \CURLOPT_HTTP_VERSION, \CURL_HTTP_VERSION_1_1); |
| 32 |
$body = \curl_exec($curlHandle); |
| 33 |
if ($body === \false) { |
| 34 |
$errorCode = \curl_errno($curlHandle); |
| 35 |
$error = \curl_error($curlHandle); |
| 36 |
if (\PHP_MAJOR_VERSION < 8) { |
| 37 |
\curl_close($curlHandle); |
| 38 |
} |
| 39 |
$message = 'cURL Error (' . $errorCode . ') ' . $error; |
| 40 |
return new Response(0, [], $message); |
| 41 |
} |
| 42 |
$statusCode = \curl_getinfo($curlHandle, \CURLINFO_HTTP_CODE); |
| 43 |
if (\PHP_MAJOR_VERSION < 8) { |
| 44 |
\curl_close($curlHandle); |
| 45 |
} |
| 46 |
return new Response($statusCode, [], ''); |
| 47 |
} |
| 48 |
} |
| 49 |
|