[IMPROVED] Further improvements on error handling

This commit is contained in:
Sebastian Grewe 2014-01-15 16:28:26 +01:00
parent f2f539ef53
commit 610e564c2f
3 changed files with 9 additions and 11 deletions

View File

@ -266,7 +266,7 @@ class BitcoinClient extends jsonRPCClient {
* @access public * @access public
* @throws BitcoinClientException * @throws BitcoinClientException
*/ */
public function __construct($scheme, $username, $password, $address = "localhost", $port = 8332, $certificate_path = '', $debug = true) { public function __construct($scheme, $username, $password, $address = "localhost", $certificate_path = '', $debug = false) {
$scheme = strtolower($scheme); $scheme = strtolower($scheme);
if ($scheme != "http" && $scheme != "https") if ($scheme != "http" && $scheme != "https")
throw new Exception("Scheme must be http or https"); throw new Exception("Scheme must be http or https");
@ -274,9 +274,6 @@ class BitcoinClient extends jsonRPCClient {
throw new Exception("Username must be non-blank"); throw new Exception("Username must be non-blank");
if (empty($password)) if (empty($password))
throw new Exception("Password must be non-blank"); throw new Exception("Password must be non-blank");
$port = (string) $port;
if (!$port || empty($port) || !is_numeric($port) || $port < 1 || $port > 65535 || floatval($port) != intval($port))
throw new Exception("Port must be an integer and between 1 and 65535");
if (!empty($certificate_path) && !is_readable($certificate_path)) if (!empty($certificate_path) && !is_readable($certificate_path))
throw new Exception("Certificate file " . $certificate_path . " is not readable"); throw new Exception("Certificate file " . $certificate_path . " is not readable");
$uri = $scheme . "://" . $username . ":" . $password . "@" . $address . "/"; $uri = $scheme . "://" . $username . ":" . $password . "@" . $address . "/";

View File

@ -9,15 +9,16 @@ if (!defined('SECURITY'))
* some basic caching functionality and some debugging * some basic caching functionality and some debugging
**/ **/
class BitcoinWrapper extends BitcoinClient { class BitcoinWrapper extends BitcoinClient {
public function __construct($type, $username, $password, $host, $debug, $memcache) { public function __construct($type, $username, $password, $host, $debug_level, $debug_object, $memcache) {
$this->type = $type; $this->type = $type;
$this->username = $username; $this->username = $username;
$this->password = $password; $this->password = $password;
$this->host = $host; $this->host = $host;
// $this->debug is already used // $this->debug is already used
$this->oDebug = $debug; $this->oDebug = $debug_object;
$this->memcache = $memcache; $this->memcache = $memcache;
return parent::__construct($this->type, $this->username, $this->password, $this->host); $debug_level > 0 ? $debug_level = true : $debug_level = false;
return parent::__construct($this->type, $this->username, $this->password, $this->host, '', $debug_level);
} }
/** /**
* Wrap variouns methods to add caching * Wrap variouns methods to add caching
@ -75,4 +76,4 @@ class BitcoinWrapper extends BitcoinClient {
} }
// Load this wrapper // Load this wrapper
$bitcoin = new BitcoinWrapper($config['wallet']['type'], $config['wallet']['username'], $config['wallet']['password'], $config['wallet']['host'], $debug, $memcache); $bitcoin = new BitcoinWrapper($config['wallet']['type'], $config['wallet']['username'], $config['wallet']['password'], $config['wallet']['host'], DEBUG, $debug, $memcache);

View File

@ -35,7 +35,7 @@ class jsonRPCClient {
* @var boolean * @var boolean
*/ */
private $debug; private $debug;
private $debug_output; private $debug_output = NULL;
/** /**
* The server URL * The server URL
@ -69,7 +69,8 @@ class jsonRPCClient {
* @return array Debug data * @return array Debug data
**/ **/
public function getDebugData() { public function getDebugData() {
return $this->debug_output; if ($this->debug) return $this->debug_output;
return false;
} }
/** /**
@ -108,7 +109,6 @@ class jsonRPCClient {
curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request); curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch); $response = curl_exec($ch);
$this->debug = true;
if ($this->debug) $this->debug_output[] = 'Response: ' . $response; if ($this->debug) $this->debug_output[] = 'Response: ' . $response;
$response = json_decode($response, true); $response = json_decode($response, true);
$resultStatus = curl_getinfo($ch); $resultStatus = curl_getinfo($ch);