Browse Source

move getJSONErrorString to global included file

master
cinnaboot 8 years ago
parent
commit
05035cf305
  1. 10
      admin.php
  2. 63
      include/getJsonErrorString.php
  3. 48
      include/tmdb_interface.php

10
admin.php

@ -18,6 +18,8 @@
declare(strict_types=1);
require_once('include/getJsonErrorString.php');
const FOLDER_PATH = '../video/unwatched';
const MAX_RECURSE_DEPTH = 5;
@ -133,10 +135,12 @@ function getUnsavedMetadata() : void
$out->path_info = $path_info;
$json = json_encode($out);
if ($json)
if ($json) {
echo $json;
else
echo '{"errors":"error enconding json in ' . __FUNCTION__ . '"}';
} else {
echo '{"errors":"' . __FUNCTION__ . ', error enconding json: '
. getJsonErrorString(json_last_error()) . '"}';
}
} else {
$out->errors = $g_errors;
echo json_encode($out);

63
include/getJsonErrorString.php

@ -0,0 +1,63 @@
<?php
/*
* This file is part of video_metadata.
*
* video_metadata is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* video_metadata is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with video_metadata. If not, see <https://www.gnu.org/licenses/>.
*/
function getJsonErrorString($error_enum) : string
{
$err = '';
switch($error_enum) {
case JSON_ERROR_NONE:
$err = 'No error has occurred';
break;
case JSON_ERROR_DEPTH:
$err = 'The maximum stack depth has been exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
$err ='Invalid or malformed JSON';
break;
case JSON_ERROR_CTRL_CHAR:
$err = 'Control character error, possibly incorrectly encoded';
break;
case JSON_ERROR_SYNTAX:
$err = 'Syntax error';
break;
case JSON_ERROR_UTF8:
$err = 'Malformed UTF-8 characters, possibly incorrectly encoded';
break;
case JSON_ERROR_RECURSION:
$err = 'One or more recursive references in the value to be encoded';
break;
case JSON_ERROR_INF_OR_NAN:
$err = 'One or more NAN or INF values in the value to be encoded';
break;
case JSON_ERROR_UNSUPPORTED_TYPE:
$err = 'A value of a type that cannot be encoded was given';
break;
case JSON_ERROR_INVALID_PROPERTY_NAME:
$err = 'A property name that cannot be encoded was given';
break;
case JSON_ERROR_UTF16:
$err = 'Malformed UTF-16 characters, possibly incorrectly encoded';
break;
}
return $err;
}
?>

48
include/tmdb_interface.php

@ -17,6 +17,9 @@
*/
require_once('getJsonErrorString.php');
class tmdb_interface
{
const BASE_API_URL = 'https://api.themoviedb.org/3';
@ -43,7 +46,7 @@ class tmdb_interface
if ($j_err !== JSON_ERROR_NONE) {
$this->errors[] = $str;
$this->errors[] = __METHOD__ . ", JSON error: " . get_json_error(json_last_error());
$this->errors[] = __METHOD__ . ", JSON error: " . getJsonErrorString(json_last_error());
}
return strlen($str);
@ -94,49 +97,6 @@ class tmdb_interface
public $errors = [];
private function get_json_error($error_enum)
{
$err = '';
switch($error_enum) {
case JSON_ERROR_NONE:
$err = 'No error has occurred';
break;
case JSON_ERROR_DEPTH:
$err = 'The maximum stack depth has been exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
$err ='Invalid or malformed JSON';
break;
case JSON_ERROR_CTRL_CHAR:
$err = 'Control character error, possibly incorrectly encoded';
break;
case JSON_ERROR_SYNTAX:
$err = 'Syntax error';
break;
case JSON_ERROR_UTF8:
$err = 'Malformed UTF-8 characters, possibly incorrectly encoded';
break;
case JSON_ERROR_RECURSION:
$err = 'One or more recursive references in the value to be encoded';
break;
case JSON_ERROR_INF_OR_NAN:
$err = 'One or more NAN or INF values in the value to be encoded';
break;
case JSON_ERROR_UNSUPPORTED_TYPE:
$err = 'A value of a type that cannot be encoded was given';
break;
case JSON_ERROR_INVALID_PROPERTY_NAME:
$err = 'A property name that cannot be encoded was given';
break;
case JSON_ERROR_UTF16:
$err = 'Malformed UTF-16 characters, possibly incorrectly encoded';
break;
}
return $err;
}
private $start_time = 0;
}

Loading…
Cancel
Save