mirror of
https://github.com/lrsjng/h5ai.git
synced 2024-09-19 20:28:47 -04:00
More refactorings.
This commit is contained in:
parent
a89db0c259
commit
8eea5f56cd
3 changed files with 22 additions and 21 deletions
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
|
|
||||||
|
|
||||||
// MISC
|
// MISC
|
||||||
putenv("LANG=en_US.UTF-8");
|
putenv("LANG=en_US.UTF-8");
|
||||||
setlocale(LC_CTYPE, "en_US.UTF-8");
|
setlocale(LC_CTYPE, "en_US.UTF-8");
|
||||||
|
|
|
@ -24,12 +24,10 @@ function has_request_param($key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
define("NO_DEFAULT", "__NO_DEFAULT_VALUE__");
|
function use_request_param($key, $default = null) {
|
||||||
|
|
||||||
function use_request_param($key, $default = NO_DEFAULT) {
|
|
||||||
|
|
||||||
if (!array_key_exists($key, $_REQUEST)) {
|
if (!array_key_exists($key, $_REQUEST)) {
|
||||||
json_fail(101, "parameter '$key' is missing", $default === NO_DEFAULT);
|
json_fail(101, "parameter '$key' is missing", $default === null);
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,18 +49,18 @@ function ends_with($sequence, $tail) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function load_commented_json($file) {
|
function load_commented_json($path) {
|
||||||
|
|
||||||
if (!file_exists($file)) {
|
if (!file_exists($path)) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$str = file_get_contents($file);
|
$content = file_get_contents($path);
|
||||||
|
|
||||||
// remove comments to get pure json
|
// remove comments to get pure json
|
||||||
$str = preg_replace("/\/\*.*?\*\/|\/\/.*?(\n|$)/s", "", $str);
|
$content = preg_replace("/\/\*.*?\*\/|\/\/.*?(\n|$)/s", "", $content);
|
||||||
|
|
||||||
return json_decode($str, true);
|
return json_decode($content, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,18 +100,22 @@ function scr_log($message, $obj = null) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
global $__TIMER_START, $__TIMER_LAST;
|
global $__TIMER_START, $__TIMER_PREV;
|
||||||
$__TIMER_START = microtime(true);
|
$__TIMER_START = microtime(true);
|
||||||
$__TIMER_LAST = $__TIMER_START;
|
$__TIMER_PREV = $__TIMER_START;
|
||||||
|
|
||||||
function time_log($message) {
|
function time_log($message) {
|
||||||
|
|
||||||
global $__TIMER_START, $__TIMER_LAST;
|
global $__TIMER_START, $__TIMER_PREV;
|
||||||
|
|
||||||
$now = microtime(true);
|
$now = microtime(true);
|
||||||
if ($__TIMER_START === $__TIMER_LAST) {
|
|
||||||
error_log("-----------------------------");
|
if ($__TIMER_START === $__TIMER_PREV) {
|
||||||
function timer_shutdown() { time_log('ex'); }
|
error_log("------------------------------");
|
||||||
register_shutdown_function('timer_shutdown');
|
register_shutdown_function(function () { time_log('ex'); });
|
||||||
}
|
}
|
||||||
error_log($message . " DT " . number_format($now - $__TIMER_LAST, 5) . " TT " . number_format($now - $__TIMER_START, 5));
|
|
||||||
$__TIMER_LAST = $now;
|
error_log($message . " DT " . number_format($now - $__TIMER_PREV, 5) . " TT " . number_format($now - $__TIMER_START, 5));
|
||||||
|
|
||||||
|
$__TIMER_PREV = $now;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,9 @@ time_log(" 1");
|
||||||
|
|
||||||
$app = new App();
|
$app = new App();
|
||||||
|
|
||||||
// time_log(" 2");
|
time_log(" 2");
|
||||||
// err_log('setup', $app->get_setup());
|
// err_log('setup', $app->get_setup());
|
||||||
time_log(" 3");
|
// time_log(" 3");
|
||||||
|
|
||||||
|
|
||||||
if (has_request_param("action")) {
|
if (has_request_param("action")) {
|
||||||
|
|
Loading…
Reference in a new issue