switching to full JSON API without POST array use, ensure all JSON operations are done with error detection

This commit is contained in:
El RIDO
2019-05-13 22:31:52 +02:00
parent be1e7babc0
commit cc1c55129f
14 changed files with 187 additions and 103 deletions

View File

@@ -33,9 +33,39 @@ class Json
public static function encode($input)
{
$jsonString = json_encode($input);
self::_detectError();
return $jsonString;
}
/**
* Returns an array with the contents as described in the given JSON input
*
* @access public
* @static
* @param string $input
* @throws Exception
* @return array
*/
public static function decode($input)
{
$array = json_decode($input, true);
self::_detectError();
return $array;
}
/**
* Detects JSON errors and raises an exception if one is found
*
* @access private
* @static
* @throws Exception
* @return void
*/
private static function _detectError()
{
$errorCode = json_last_error();
if ($errorCode === JSON_ERROR_NONE) {
return $jsonString;
return;
}
$message = 'A JSON error occurred';