@@ -16,8 +16,9 @@ private static function caBundle() {
1616 return __DIR__ . "/../data/cacert.pem " ;
1717 }
1818
19- function __construct ($ key , $ appIdentifier = NULL ) {
19+ function __construct ($ key , $ appIdentifier = NULL , $ proxy = NULL ) {
2020 $ userAgent = join (" " , array_filter (array (self ::userAgent (), $ appIdentifier )));
21+
2122 $ this ->options = array (
2223 CURLOPT_BINARYTRANSFER => true ,
2324 CURLOPT_RETURNTRANSFER => true ,
@@ -27,9 +28,33 @@ function __construct($key, $appIdentifier = NULL) {
2728 CURLOPT_SSL_VERIFYPEER => true ,
2829 CURLOPT_USERAGENT => $ userAgent ,
2930 );
31+
32+ if ($ proxy ) {
33+ $ parts = parse_url ($ proxy );
34+ if (isset ($ parts ["host " ])) {
35+ $ this ->options [CURLOPT_PROXYTYPE ] = CURLPROXY_HTTP ;
36+ $ this ->options [CURLOPT_PROXY ] = $ parts ["host " ];
37+ } else {
38+ throw new ConnectionException ("Invalid proxy " );
39+ }
40+
41+ if (isset ($ parts ["port " ])) {
42+ $ this ->options [CURLOPT_PROXYPORT ] = $ parts ["port " ];
43+ }
44+
45+ $ creds = "" ;
46+ if (isset ($ parts ["user " ])) $ creds .= $ parts ["user " ];
47+ if (isset ($ parts ["pass " ])) $ creds .= ": " . $ parts ["pass " ];
48+
49+ if ($ creds ) {
50+ $ this ->options [CURLOPT_PROXYAUTH ] = CURLAUTH_ANY ;
51+ $ this ->options [CURLOPT_PROXYUSERPWD ] = $ creds ;
52+ }
53+ }
3054 }
3155
32- function request ($ method , $ url , $ body = NULL , $ header = array ()) {
56+ function request ($ method , $ url , $ body = NULL ) {
57+ $ header = array ();
3358 if (is_array ($ body )) {
3459 if (!empty ($ body )) {
3560 $ body = json_encode ($ body );
@@ -40,6 +65,12 @@ function request($method, $url, $body = NULL, $header = array()) {
4065 }
4166
4267 $ request = curl_init ();
68+ if ($ request === false || $ request === null ) {
69+ throw new ConnectionException (
70+ "Error while connecting: curl extension is not functional or disabled. "
71+ );
72+ }
73+
4374 curl_setopt_array ($ request , $ this ->options );
4475
4576 $ url = strtolower (substr ($ url , 0 , 6 )) == "https: " ? $ url : self ::API_ENDPOINT . $ url ;
0 commit comments