Skip to content

Commit

Permalink
API client class v1.1.86
Browse files Browse the repository at this point in the history
- fixes issue with curl_init() returning CurlHandle class objects instead of curl handlers with PHP 8 and higher
  • Loading branch information
malle-pietje committed Feb 10, 2024
1 parent 4b175dd commit bd39c32
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @package UniFi_Controller_API_Client_Class
* @author Art of WiFi <[email protected]>
* @version Release: 1.1.85
* @version Release: 1.1.86
* @license This class is subject to the MIT license that is bundled with this package in the file LICENSE.md
* @example This directory in the package repository contains a collection of examples:
* https://github.com/Art-of-WiFi/UniFi-API-client/tree/master/examples
Expand All @@ -25,7 +25,7 @@ class Client
*
* NOTE: do **not** modify the values here, instead use the constructor or the getter and setter functions/methods
*/
const CLASS_VERSION = '1.1.85';
const CLASS_VERSION = '1.1.86';
protected string $baseurl = 'https://127.0.0.1:8443';
protected string $user = '';
protected string $password = '';
Expand Down Expand Up @@ -4212,37 +4212,40 @@ protected function exec_curl(string $path, $payload = null)
/**
* Create and return a new cURL handle
*
* @return object|resource|bool cURL handle (object or resource) upon success, false upon failure
* @return object|resource|bool CurlHandle object with PHP 8, or a resource for lower PHP versions upon
* success, false upon failure
*/
protected function get_curl_handle()
{
$ch = curl_init();
if (is_resource($ch)) {
$curl_options = [
CURLOPT_PROTOCOLS => CURLPROTO_HTTPS,
CURLOPT_HTTP_VERSION => $this->curl_http_version,
CURLOPT_SSL_VERIFYPEER => $this->curl_ssl_verify_peer,
CURLOPT_SSL_VERIFYHOST => $this->curl_ssl_verify_host,
CURLOPT_CONNECTTIMEOUT => $this->curl_connect_timeout,
CURLOPT_TIMEOUT => $this->curl_request_timeout,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_HEADERFUNCTION => [$this, 'response_header_callback'],
];

if ($this->debug) {
$curl_options[CURLOPT_VERBOSE] = true;
}
if (!is_resource($ch) && !is_object($ch)) {
return false;
}

if (!empty($this->cookies)) {
$curl_options[CURLOPT_COOKIESESSION] = true;
$curl_options[CURLOPT_COOKIE] = $this->cookies;
}
$curl_options = [
CURLOPT_PROTOCOLS => CURLPROTO_HTTPS,
CURLOPT_HTTP_VERSION => $this->curl_http_version,
CURLOPT_SSL_VERIFYPEER => $this->curl_ssl_verify_peer,
CURLOPT_SSL_VERIFYHOST => $this->curl_ssl_verify_host,
CURLOPT_CONNECTTIMEOUT => $this->curl_connect_timeout,
CURLOPT_TIMEOUT => $this->curl_request_timeout,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_HEADERFUNCTION => [$this, 'response_header_callback'],
];

curl_setopt_array($ch, $curl_options);
return $ch;
if ($this->debug) {
$curl_options[CURLOPT_VERBOSE] = true;
}

return false;
if (!empty($this->cookies)) {
$curl_options[CURLOPT_COOKIESESSION] = true;
$curl_options[CURLOPT_COOKIE] = $this->cookies;
}

curl_setopt_array($ch, $curl_options);

return $ch;
}
}

0 comments on commit bd39c32

Please sign in to comment.