Json.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php declare(strict_types=1);
  2. /**
  3. * PrivateBin
  4. *
  5. * a zero-knowledge paste bin
  6. *
  7. * @link https://github.com/PrivateBin/PrivateBin
  8. * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
  9. * @license https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
  10. */
  11. namespace PrivateBin;
  12. /**
  13. * Json
  14. *
  15. * Provides JSON functions in an object oriented way.
  16. */
  17. class Json
  18. {
  19. /**
  20. * Returns a string containing the JSON representation of the given input
  21. *
  22. * @access public
  23. * @static
  24. * @param mixed $input
  25. * @throws JsonException
  26. * @return string
  27. */
  28. public static function encode(&$input)
  29. {
  30. return json_encode($input, JSON_THROW_ON_ERROR);
  31. }
  32. /**
  33. * Returns an array with the contents as described in the given JSON input
  34. *
  35. * @access public
  36. * @static
  37. * @param string $input
  38. * @throws JsonException
  39. * @return mixed
  40. */
  41. public static function decode(&$input)
  42. {
  43. return json_decode($input, true, 10, JSON_THROW_ON_ERROR);
  44. }
  45. }