From 12421e09ea5295bf8c41a71e3aa5e800d863c043 Mon Sep 17 00:00:00 2001 From: japatel Date: Sat, 10 Jan 2015 17:21:21 -0600 Subject: [PATCH] PayPal Model toJSON to determine encoding based on PHP Version - Allows Preetifying JSON output - toString prints a nice looking JSON now --- lib/PayPal/Common/PayPalModel.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/PayPal/Common/PayPalModel.php b/lib/PayPal/Common/PayPalModel.php index 1f294a04..ec1939aa 100644 --- a/lib/PayPal/Common/PayPalModel.php +++ b/lib/PayPal/Common/PayPalModel.php @@ -245,6 +245,9 @@ public function toJSON($options = 0) // Because of PHP Version 5.3, we cannot use JSON_UNESCAPED_SLASHES option // Instead we would use the str_replace command for now. // TODO: Replace this code with return json_encode($this->toArray(), $options | 64); once we support PHP >= 5.4 + if (version_compare(phpversion(), '5.4.0', '>=') === true) { + return json_encode($this->toArray(), $options | 64); + } return str_replace('\\/', '/', json_encode($this->toArray(), $options)); } @@ -255,6 +258,6 @@ public function toJSON($options = 0) */ public function __toString() { - return json_encode($this->toArray()); + return $this->toJSON(128); } }