@@ -19,7 +19,7 @@ private static function caBundle() {
1919 return __DIR__ . "/../data/cacert.pem " ;
2020 }
2121
22- function __construct ($ key , $ appIdentifier = NULL , $ proxy = NULL ) {
22+ function __construct ($ key , $ app_identifier = NULL , $ proxy = NULL ) {
2323 $ curl = curl_version ();
2424
2525 if (!($ curl ["features " ] & CURL_VERSION_SSL )) {
@@ -31,15 +31,19 @@ function __construct($key, $appIdentifier = NULL, $proxy = NULL) {
3131 throw new ClientException ("Your curl version {$ version } is outdated; please upgrade to 7.18.1 or higher " );
3232 }
3333
34- $ userAgent = join (" " , array_filter (array (self ::userAgent (), $ appIdentifier )));
35-
34+ # Set minimum TLS version to 1.2, CURL_SSLVERSION_TLSv1_2 is not available in curl < 7.34.0
35+ # Additionally old PHP versions may not support this constant
36+ $ tlsVersion = ($ curl ["version_number " ] < 0x072200 )
37+ ? 6
38+ : (defined ('CURL_SSLVERSION_TLSv1_2 ' ) ? CURL_SSLVERSION_TLSv1_2 : 6 );
3639 $ this ->options = array (
3740 CURLOPT_RETURNTRANSFER => true ,
3841 CURLOPT_HEADER => true ,
3942 CURLOPT_USERPWD => $ key ? ("api: " . $ key ) : NULL ,
4043 CURLOPT_CAINFO => self ::caBundle (),
4144 CURLOPT_SSL_VERIFYPEER => true ,
42- CURLOPT_USERAGENT => $ userAgent ,
45+ CURLOPT_USERAGENT => join (" " , array_filter (array (self ::userAgent (), $ app_identifier ))),
46+ CURLOPT_SSLVERSION => $ tlsVersion ,
4347 );
4448
4549 if ($ proxy ) {
@@ -108,7 +112,11 @@ function request($method, $url, $body = NULL) {
108112 if (is_string ($ response )) {
109113 $ status = curl_getinfo ($ request , CURLINFO_HTTP_CODE );
110114 $ headerSize = curl_getinfo ($ request , CURLINFO_HEADER_SIZE );
111- curl_close ($ request );
115+ if (PHP_VERSION_ID < 80000 ) {
116+ curl_close ($ request );
117+ } else {
118+ unset($ request );
119+ }
112120
113121 $ headers = self ::parseHeaders (substr ($ response , 0 , $ headerSize ));
114122 $ responseBody = substr ($ response , $ headerSize );
@@ -177,7 +185,11 @@ function request($method, $url, $body = NULL) {
177185 return (object ) array ("body " => $ responseBody , "headers " => $ headers );
178186 } else {
179187 $ message = sprintf ("%s (#%d) " , curl_error ($ request ), curl_errno ($ request ));
180- curl_close ($ request );
188+ if (PHP_VERSION_ID < 80000 ) {
189+ curl_close ($ request );
190+ } else {
191+ unset($ request );
192+ }
181193 if ($ retries > 0 ) continue ;
182194 throw new ConnectionException ("Error while connecting: " . $ message );
183195 }
0 commit comments