mirror of
https://github.com/jonathan-martz/pocketbase-php-sdk.git
synced 2026-04-03 07:27:42 +00:00
31 lines
775 B
PHP
31 lines
775 B
PHP
<?php
|
|
|
|
namespace PocketBase;
|
|
|
|
class HttpClient
|
|
{
|
|
public function doRequest(string $url, string $method, $bodyParams = [], ?string $token = null): string
|
|
{
|
|
$ch = curl_init();
|
|
|
|
if ($token != '') {
|
|
$headers = array(
|
|
'Content-Type:application/json',
|
|
'Authorization: ' . $token
|
|
);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
}
|
|
|
|
if ($bodyParams) {
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyParams);
|
|
}
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
|
$output = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
return $output;
|
|
}
|
|
} |