Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Commit

Permalink
PayPal Model toJSON to determine encoding based on PHP Version
Browse files Browse the repository at this point in the history
- Allows Preetifying JSON output
- toString prints a nice looking JSON now
  • Loading branch information
japatel committed Jan 10, 2015
1 parent 932cc8f commit 12421e0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/PayPal/Common/PayPalModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -255,6 +258,6 @@ public function toJSON($options = 0)
*/
public function __toString()
{
return json_encode($this->toArray());
return $this->toJSON(128);
}
}

0 comments on commit 12421e0

Please sign in to comment.