ActionController: helper method for JSON errors

This commit is contained in:
Thomas Gelf 2016-03-01 04:25:14 +01:00
parent 8b3d72a04a
commit 1329d01280
1 changed files with 21 additions and 0 deletions

View File

@ -166,6 +166,27 @@ abstract class ActionController extends Controller
$this->prepareTable($name)->render('list/table', null, true);
}
// TODO: just return json_last_error_msg() for PHP >= 5.5.0
protected function getLastJsonError()
{
switch (json_last_error()) {
case JSON_ERROR_DEPTH:
return 'The maximum stack depth has been exceeded';
case JSON_ERROR_CTRL_CHAR:
return 'Control character error, possibly incorrectly encoded';
case JSON_ERROR_STATE_MISMATCH:
return 'Invalid or malformed JSON';
case JSON_ERROR_SYNTAX:
return 'Syntax error';
case JSON_ERROR_UTF8:
return 'Malformed UTF-8 characters, possibly incorrectly encoded';
default:
return 'An error occured when parsing a JSON string';
}
return $this;
}
protected function api($endpointName = null)
{
if ($this->api === null) {