@@ -31,12 +31,15 @@ class RestApi
31
31
32
32
protected $ enumCustomFields ;
33
33
34
- public function __construct ($ baseUrl , $ username , $ password )
34
+ protected $ proxy ;
35
+
36
+ public function __construct ($ baseUrl , $ username , $ password , ?string $ proxy )
35
37
{
36
38
$ this ->username = $ username ;
37
39
$ this ->password = $ password ;
38
40
$ this ->baseUrlForLink = $ baseUrl ;
39
41
$ this ->baseUrl = \rtrim ($ baseUrl , '/ ' ) . '/rest ' ;
42
+ $ this ->proxy = $ proxy ;
40
43
$ this ->serverInfo = $ this ->get ('serverInfo ' )->getResult ();
41
44
}
42
45
@@ -61,8 +64,9 @@ public static function fromConfig()
61
64
62
65
$ user = $ config ->get ('api ' , 'username ' );
63
66
$ pass = $ config ->get ('api ' , 'password ' );
67
+ $ proxy = $ config ->get ('api ' , 'proxy ' );
64
68
65
- $ api = new static ($ url , $ user , $ pass );
69
+ $ api = new static ($ url , $ user , $ pass, $ proxy );
66
70
67
71
return $ api ;
68
72
}
@@ -450,6 +454,10 @@ protected function request($method, $url, $body = null)
450
454
451
455
$ curl = $ this ->curl ();
452
456
457
+ if ($ this ->proxy ) {
458
+ $ opts [CURLOPT_PROXY ] = $ this ->proxy ;
459
+ }
460
+
453
461
curl_setopt_array ($ curl , $ opts );
454
462
// TODO: request headers, validate status code
455
463
0 commit comments