PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.21
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.21
1.10.24 1.10.23 1.10.22 1.10.21 1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 All 168 releases
woocommerce-pos / vendor_prefixed / sentry / sentry / src / Spotlight / SpotlightClient.php

SpotlightClient.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.21, at vendor_prefixed/sentry/sentry/src/Spotlight/SpotlightClient.php

49 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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