Skip to content

Commit

Permalink
Update RestClient
Browse files Browse the repository at this point in the history
Resolves a deprecation notice from PHP 8.2+.
  • Loading branch information
Freaky committed Apr 1, 2024
1 parent fc3a0f2 commit e666bd1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions restclient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class RestClient implements Iterator, ArrayAccess {

public $options;
public $handle; // cURL resource handle.
public $url;

// Populated after execution:
public $response; // Response body.
Expand Down Expand Up @@ -148,7 +149,7 @@ public function execute(string $url, string $method='GET', $parameters=[], array
$headers = array_merge($client->options['headers'], $headers);
foreach($headers as $key => $values){
foreach(is_array($values)? $values : [$values] as $value){
$curlopt[CURLOPT_HTTPHEADER][] = sprintf("%s:%s", $key, $value);
$curlopt[CURLOPT_HTTPHEADER][] = sprintf("%s: %s", $key, $value);
}
}
}
Expand Down Expand Up @@ -187,9 +188,9 @@ public function execute(string $url, string $method='GET', $parameters=[], array
}

if($client->options['base_url']){
if($client->url[0] !== '/' && substr($client->options['base_url'], -1) !== '/')
$client->url = '/' . $client->url;
$client->url = $client->options['base_url'] . $client->url;
$client->url = sprintf("%s/%s",
rtrim((string) $client->options['base_url'], '/'),
ltrim((string) $client->url, '/'));
}
$curlopt[CURLOPT_URL] = $client->url;

Expand All @@ -201,7 +202,9 @@ public function execute(string $url, string $method='GET', $parameters=[], array
}
curl_setopt_array($client->handle, $curlopt);

$client->parse_response(curl_exec($client->handle));
$response = curl_exec($client->handle);
if($response !== FALSE)
$client->parse_response($response);
$client->info = (object) curl_getinfo($client->handle);
$client->error = curl_error($client->handle);

Expand Down

0 comments on commit e666bd1

Please sign in to comment.