mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-22 08:05:34 +08:00
initial 2.0.0-a3 commit
This commit is contained in:
@@ -5,9 +5,6 @@ namespace ZM\Utils;
|
||||
|
||||
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Annotation\Swoole\OnSave;
|
||||
use ZM\Store\ZMBuf;
|
||||
|
||||
class DataProvider
|
||||
{
|
||||
@@ -24,57 +21,10 @@ class DataProvider
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getDataConfig() {
|
||||
return CONFIG_DIR;
|
||||
}
|
||||
|
||||
public static function addSaveBuffer($buf_name, $sub_folder = null) {
|
||||
$name = ($sub_folder ?? "") . "/" . $buf_name . ".json";
|
||||
self::$buffer_list[$buf_name] = $name;
|
||||
Console::debug("Added " . $buf_name . " at $sub_folder");
|
||||
ZMBuf::set($buf_name, self::getJsonData($name));
|
||||
}
|
||||
|
||||
public static function saveBuffer() {
|
||||
$head = Console::setColor(date("[H:i:s] ") . "[V] Saving buffer......", "blue");
|
||||
if (Console::getLevel() >= 3)
|
||||
echo $head;
|
||||
foreach (self::$buffer_list as $k => $v) {
|
||||
Console::debug("Saving " . $k . " to " . $v);
|
||||
self::setJsonData($v, ZMBuf::get($k));
|
||||
}
|
||||
foreach (ZMBuf::$events[OnSave::class] ?? [] as $v) {
|
||||
$c = $v->class;
|
||||
$method = $v->method;
|
||||
$class = new $c();
|
||||
Console::debug("Calling @OnSave: $c -> $method");
|
||||
$class->$method();
|
||||
}
|
||||
if (Console::getLevel() >= 3)
|
||||
echo Console::setColor("saved", "blue") . PHP_EOL;
|
||||
}
|
||||
|
||||
public static function getFrameworkLink() {
|
||||
return ZMConfig::get("global", "http_reverse_link");
|
||||
}
|
||||
|
||||
public static function getJsonData(string $string) {
|
||||
if (!file_exists(self::getDataConfig() . $string)) return [];
|
||||
return json_decode(file_get_contents(self::getDataConfig() . $string), true);
|
||||
}
|
||||
|
||||
public static function setJsonData($filename, array $args) {
|
||||
$pathinfo = pathinfo($filename);
|
||||
if (!is_dir(self::getDataConfig() . $pathinfo["dirname"])) {
|
||||
Console::debug("Making Directory: " . self::getDataConfig() . $pathinfo["dirname"]);
|
||||
mkdir(self::getDataConfig() . $pathinfo["dirname"]);
|
||||
}
|
||||
$r = file_put_contents(self::getDataConfig() . $filename, json_encode($args, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING));
|
||||
if ($r === false) {
|
||||
Console::warning("无法保存文件: " . $filename);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getDataFolder() {
|
||||
return ZM_DATA;
|
||||
}
|
||||
|
||||
@@ -52,10 +52,10 @@ class HttpUtil
|
||||
}
|
||||
if (ZMConfig::get("global", "static_file_server")["status"]) {
|
||||
HttpUtil::handleStaticPage($request->server["request_uri"], $response);
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return !isset($node["route"]) ? false : true;
|
||||
}
|
||||
|
||||
public static function getHttpCodePage(int $http_code) {
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace ZM\Utils;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Psy\Shell;
|
||||
use Swoole\Event;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Framework;
|
||||
@@ -35,8 +36,9 @@ class Terminal
|
||||
$class->$function_name();
|
||||
return true;
|
||||
case 'psysh':
|
||||
if (Framework::$argv["disable-coroutine"])
|
||||
eval(\Psy\sh());
|
||||
if (Framework::$argv["disable-coroutine"]) {
|
||||
(new Shell())->run();
|
||||
}
|
||||
else
|
||||
Console::error("Only \"--disable-coroutine\" mode can use psysh!!!");
|
||||
return true;
|
||||
|
||||
@@ -30,13 +30,14 @@ class ZMUtil
|
||||
public static function reload($delay = 800) {
|
||||
Console::info(Console::setColor("Reloading server...", "gold"));
|
||||
usleep($delay * 1000);
|
||||
foreach (ZMBuf::get("wait_api", []) as $k => $v) {
|
||||
if ($v["result"] === null) Co::resume($v["coroutine"]);
|
||||
foreach (LightCache::getAll() as $k => $v) {
|
||||
if (mb_substr($k, 0, 8) == "wait_api")
|
||||
if ($v["result"] === null) Co::resume($v["coroutine"]);
|
||||
}
|
||||
foreach (server()->connections as $v) {
|
||||
server()->close($v);
|
||||
}
|
||||
DataProvider::saveBuffer();
|
||||
//DataProvider::saveBuffer();
|
||||
Timer::clearAll();
|
||||
server()->reload();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user