finish support with otane

This commit is contained in:
xiaomlove
2022-03-20 22:14:00 +08:00
parent a5ea51de55
commit 0e4544459f
39 changed files with 427 additions and 104 deletions

View File

@@ -1,4 +1,7 @@
<?php
use JetBrains\PhpStorm\Pure;
function get_global_sp_state()
{
global $Cache;
@@ -155,10 +158,13 @@ function nexus_dd($vars)
*/
function do_log($log, $level = 'info')
{
static $uid, $passkey, $env, $sequence, $setLogLevel;
static $env, $setLogLevel;
if (is_null($setLogLevel)) {
$setLogLevel = nexus_env('LOG_LEVEL', 'debug');
}
if (is_null($env)) {
$env = nexus_env('APP_ENV', 'production');
}
$logLevels = ['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'];
$setLogLevelKey = array_search($setLogLevel, $logLevels);
$currentLogLevelKey = array_search($level, $logLevels);
@@ -175,32 +181,25 @@ function do_log($log, $level = 'info')
if (($fd = fopen($logFile, 'a')) === false) {
$fd = fopen(sys_get_temp_dir() . '/nexus.log', 'a');
}
if (is_null($uid)) {
$sequence = 0;
if (IN_NEXUS) {
global $CURUSER;
$user = $CURUSER;
$uid = $user['id'] ?? 0;
$passkey = $user['passkey'] ?? $_REQUEST['passkey'] ?? $_REQUEST['authkey'] ?? '';
$env = nexus_env('APP_ENV');
} else {
$user = \Illuminate\Support\Facades\Auth::user();
$uid = $user->id ?? 0;
$passkey = $user->passkey ?? $_REQUEST['passkey'] ?? $_REQUEST['authkey'] ?? '';
$env = env('APP_ENV');
}
if (IN_NEXUS) {
global $CURUSER;
$user = $CURUSER;
$uid = $user['id'] ?? 0;
$passkey = $user['passkey'] ?? $_REQUEST['passkey'] ?? $_REQUEST['authkey'] ?? '';
} else {
$sequence++;
$user = \Illuminate\Support\Facades\Auth::user();
$uid = $user->id ?? 0;
$passkey = $user->passkey ?? request('passkey', request('authkey', ''));
}
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$content = sprintf(
"[%s] [%s] [%s] [%s] [%s] [%s] %s.%s %s:%s %s%s%s %s%s",
date('Y-m-d H:i:s'),
defined('REQUEST_ID') ? REQUEST_ID : '',
nexus() ? nexus()->getRequestId() : 'NO_REQUEST_ID',
nexus() ? nexus()->getLogSequence() : 0,
sprintf('%.3f', microtime(true) - (nexus() ? nexus()->getStartTimestamp() : 0)),
$uid,
$passkey,
$sequence,
sprintf('%.3f', microtime(true) - NEXUS_START),
$env, $level,
$backtrace[0]['file'] ?? '',
$backtrace[0]['line'] ?? '',
@@ -212,6 +211,9 @@ function do_log($log, $level = 'info')
);
fwrite($fd, $content);
fclose($fd);
if (nexus()) {
nexus()->incrementLogSequence();
}
}
function getLogFile()
@@ -483,26 +485,19 @@ function api(...$args)
$msg = $args[1];
$data = $args[2];
}
if (defined('LARAVEL_START')) {
$start = LARAVEL_START;
if ($data instanceof \Illuminate\Http\Resources\Json\ResourceCollection || $data instanceof \Illuminate\Http\Resources\Json\JsonResource) {
$data = $data->response()->getData(true);
if (isset($data['data']) && count($data) == 1) {
//单纯的集合,无分页等其数据
$data = $data['data'];
}
if ($data instanceof \Illuminate\Http\Resources\Json\ResourceCollection || $data instanceof \Illuminate\Http\Resources\Json\JsonResource) {
$data = $data->response()->getData(true);
if (isset($data['data']) && count($data) == 1) {
//单纯的集合,无分页等其数据
$data = $data['data'];
}
} elseif (defined('NEXUS_START')) {
$start = NEXUS_START;
} else {
throw new \RuntimeException("no constant START is defined.");
}
return [
'ret' => (int)$ret,
'msg' => (string)$msg,
'data' => $data,
'time' => (float)number_format(microtime(true) - $start, 3),
'rid' => REQUEST_ID,
'time' => (float)number_format(microtime(true) - nexus()->getStartTimestamp(), 3),
'rid' => nexus()->getRequestId(),
];
}
@@ -669,3 +664,8 @@ function get_hr_ratio($uped, $downed)
return $ratio;
}
function nexus()
{
return \Nexus\Nexus::instance();
}