From 49bd7bd70acdecb64f9f8b5f04ad5c184453a0fc Mon Sep 17 00:00:00 2001 From: Trevor SIbanda Date: Wed, 1 Apr 2015 16:51:14 +0200 Subject: [PATCH] Added option for json_decode return type --- libraries/nexmo.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/libraries/nexmo.php b/libraries/nexmo.php index 78c397a..bd74266 100644 --- a/libraries/nexmo.php +++ b/libraries/nexmo.php @@ -41,6 +41,8 @@ class nexmo private $_api_key; private $_api_secret; private $_format = 'json'; + //either assoc for (assoc array) or class for ( stdClass ) + private $_json_format = 'assoc'; // debug mode private $_enable_debug = false; @@ -611,6 +613,20 @@ public function set_format($format = 'json') return $this; } + + /** + * Set the json return format + * + * @param String $ JSON format, assoc or class for ASSOC ARRAY and stdClass respectively + * + * @return NULL + */ + public function set_json_format( $format = 'assoc' ) + { + if( $format !== 'assoc' and $format !== 'class' ) + $format = 'assoc'; + $this->_json_format = $format; + } /** * @@ -626,7 +642,10 @@ protected function response() break; case 'json': default: - $response_obj = json_decode($this->_http_response); + { + $is_assoc = ( $this->_json_format === 'assoc' ) ? TRUE : FALSE; + $response_obj = json_decode($this->_http_response , $is_assoc ); + } } return $response_obj;