@@ -38,7 +38,7 @@ class JsonRPCClient
3838 *
3939 * @var boolean
4040 */
41- private $ debug ;
41+ private $ debug = false ;
4242
4343 /**
4444 * The server URL
@@ -47,6 +47,13 @@ class JsonRPCClient
4747 */
4848 private $ url ;
4949
50+ /**
51+ * Proxy to be used
52+ *
53+ * @var string
54+ */
55+ private $ proxy = null ;
56+
5057 /**
5158 * The request id
5259 *
@@ -74,15 +81,13 @@ class JsonRPCClient
7481 *
7582 * @param string $url
7683 * @param boolean $debug
84+ * @param string $proxy
7785 */
78- public function __construct ($ url , $ debug = false )
86+ public function __construct ($ url , $ debug = false , $ proxy = null )
7987 {
80- // server URL
8188 $ this ->url = $ url ;
82- // proxy
83- empty ($ proxy ) ? $ this ->proxy = '' : $ this ->proxy = $ proxy ;
84- // debug state
85- empty ($ debug ) ? $ this ->debug = false : $ this ->debug = true ;
89+ $ this ->proxy = $ proxy ;
90+ $ this ->debug = ($ this ->debug === true );
8691 // message id
8792 $ this ->id = 1 ;
8893 }
@@ -150,6 +155,9 @@ public function __call($method, $params)
150155 curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
151156 curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT , 5 );
152157 curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ request );
158+ if ($ this ->proxy !== null && trim ($ this ->proxy ) !== '' ) {
159+ curl_setopt ($ ch , CURLOPT_PROXY , $ this ->proxy );
160+ }
153161 $ response = curl_exec ($ ch );
154162 if ($ response === false ) {
155163 throw new \Exception ('Unable to connect to ' . $ this ->url );
0 commit comments