fix some DataProvider bug.

This commit is contained in:
whale
2020-05-06 17:19:59 +08:00
parent 181f6430a4
commit 9b3a2e5296
8 changed files with 28 additions and 19 deletions

View File

@@ -14,9 +14,9 @@ class DataProvider
public static function getWorkingDir() {
global $is_phar;
if($is_phar === true) {
if ($is_phar === true) {
return realpath('.');
} else {
} else {
return WORKING_DIR;
}
}
@@ -28,7 +28,8 @@ class DataProvider
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");
Console::debug("Added " . $buf_name . " at $sub_folder");
var_dump(self::$buffer_list);
ZMBuf::set($buf_name, self::getJsonData($name));
}
@@ -37,6 +38,7 @@ class DataProvider
if (ZMBuf::$atomics["info_level"]->get() >= 3)
echo $head;
foreach (self::$buffer_list as $k => $v) {
Console::debug("Saving " . $k . " to " . $v);
self::setJsonData($v, ZMBuf::get($k));
}
if (ZMBuf::$atomics["info_level"]->get() >= 3)
@@ -53,8 +55,12 @@ class DataProvider
}
private static function setJsonData($filename, array $args) {
Console::debug("Saving ".$filename);
file_put_contents(self::getDataConfig() . $filename, json_encode($args, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING));
$pathinfo = pathinfo($filename);
if (!is_dir($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() {

View File

@@ -68,7 +68,7 @@ class FrameworkLoader
$this->server->set($settings);
$this->server->on("WorkerStart", [$this, "onWorkerStart"]);
$this->server->on("message", function ($server, Frame $frame) {
Console::debug("Calling Swoole \"message\" event from fd=" . $frame->fd);
Console::debug("Calling Swoole \"message\" from fd=" . $frame->fd);
EventHandler::callSwooleEvent("message", $server, $frame);
});
$this->server->on("request", function ($request, $response) {

View File

@@ -5,7 +5,7 @@ use Framework\DataProvider;
use Framework\ZMBuf;
use ZM\Context\ContextInterface;
function isPharMode(){
function isPharMode() {
return substr(__DIR__, 0, 7) == 'phar://';
}
@@ -162,7 +162,8 @@ function matchArgs($pattern, $context) {
function set_coroutine_params($array) {
$cid = Co::getCid();
if ($cid == -1) die("Cannot set coroutine params at none coroutine mode.");
ZMBuf::$context[$cid] = $array;
if(isset(ZMBuf::$context[$cid])) ZMBuf::$context[$cid] = array_merge(ZMBuf::$context[$cid], $array);
else ZMBuf::$context[$cid] = $array;
foreach (ZMBuf::$context as $c => $v) {
if (!Co::exists($c)) unset(ZMBuf::$context[$c]);
}
@@ -175,16 +176,18 @@ function context() {
$cid = Co::getCid();
$c_class = ZMBuf::globals("context_class");
if (isset(ZMBuf::$context[$cid])) {
return new $c_class(ZMBuf::$context[$cid], $cid);
return new $c_class($cid);
} else {
while (($pcid = Co::getPcid($cid)) !== -1) {
if (isset(ZMBuf::$context[$cid])) return new $c_class(ZMBuf::$context[$cid], $cid);
if (isset(ZMBuf::$context[$cid])) return new $c_class($cid);
else $cid = $pcid;
}
return null;
}
}
function ctx() { return context(); }
function debug($msg) {
if (ZMBuf::$atomics["info_level"]->get() >= 4)
Console::log(date("[H:i:s] ") . "[D] " . $msg, 'gray');