mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-24 00:55:35 +08:00
Add other config file loader.
Fix SaveBuffer bug.
This commit is contained in:
@@ -34,7 +34,7 @@ class ZMBuf
|
|||||||
static $globals = null;
|
static $globals = null;
|
||||||
|
|
||||||
// swoole server操作对象,每个进程均分配
|
// swoole server操作对象,每个进程均分配
|
||||||
/** @var swoole_websocket_server $server */
|
/** @var \swoole_websocket_server $server */
|
||||||
static $server;
|
static $server;
|
||||||
/** @var array Http请求uri路径根节点 */
|
/** @var array Http请求uri路径根节点 */
|
||||||
public static $req_mapping_node;
|
public static $req_mapping_node;
|
||||||
@@ -52,31 +52,56 @@ class ZMBuf
|
|||||||
/** @var Atomic[] */
|
/** @var Atomic[] */
|
||||||
public static $atomics;
|
public static $atomics;
|
||||||
public static $req_mapping = [];
|
public static $req_mapping = [];
|
||||||
|
public static $config = [];
|
||||||
|
|
||||||
static function get($name, $default = null) { return self::$cache[$name] ?? $default; }
|
static function get($name, $default = null) {
|
||||||
|
return self::$cache[$name] ?? $default;
|
||||||
|
}
|
||||||
|
|
||||||
static function set($name, $value) { self::$cache[$name] = $value; }
|
static function set($name, $value) {
|
||||||
|
self::$cache[$name] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
static function append($name, $value) { self::$cache[$name][] = $value; }
|
static function append($name, $value) {
|
||||||
|
self::$cache[$name][] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
static function appendKey($name, $key, $value) { self::$cache[$name][$key] = $value; }
|
static function appendKey($name, $key, $value) {
|
||||||
|
self::$cache[$name][$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
static function appendKeyInKey($name, $key, $value) { self::$cache[$name][$key][] = $value; }
|
static function appendKeyInKey($name, $key, $value) {
|
||||||
|
self::$cache[$name][$key][] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
static function unsetCache($name) { unset(self::$cache[$name]); }
|
static function unsetCache($name) {
|
||||||
|
unset(self::$cache[$name]);
|
||||||
|
}
|
||||||
|
|
||||||
static function unsetByValue($name, $vale) {
|
static function unsetByValue($name, $vale) {
|
||||||
$key = array_search($vale, self::$cache[$name]);
|
$key = array_search($vale, self::$cache[$name]);
|
||||||
array_splice(self::$cache[$name], $key, 1);
|
array_splice(self::$cache[$name], $key, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function isset($name) { return isset(self::$cache[$name]); }
|
static function isset($name) {
|
||||||
|
return isset(self::$cache[$name]);
|
||||||
|
}
|
||||||
|
|
||||||
static function array_key_exists($name, $key) { return isset(self::$cache[$name][$key]); }
|
static function array_key_exists($name, $key) {
|
||||||
|
return isset(self::$cache[$name][$key]);
|
||||||
|
}
|
||||||
|
|
||||||
static function in_array($name, $val) { return in_array($val, self::$cache[$name]); }
|
static function in_array($name, $val) {
|
||||||
|
return in_array($val, self::$cache[$name]);
|
||||||
|
}
|
||||||
|
|
||||||
static function globals($key) { return self::$globals->get($key); }
|
static function globals($key) {
|
||||||
|
return self::$globals->get($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function config($config_name) {
|
||||||
|
return self::$config ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
public static function resetCache() {
|
public static function resetCache() {
|
||||||
self::$cache = [];
|
self::$cache = [];
|
||||||
@@ -88,7 +113,7 @@ class ZMBuf
|
|||||||
* 初始化atomic计数器
|
* 初始化atomic计数器
|
||||||
*/
|
*/
|
||||||
public static function initAtomic() {
|
public static function initAtomic() {
|
||||||
foreach(ZMBuf::globals("init_atomics") as $k => $v) {
|
foreach (ZMBuf::globals("init_atomics") as $k => $v) {
|
||||||
self::$atomics[$k] = new Atomic($v);
|
self::$atomics[$k] = new Atomic($v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,6 @@ class SaveBuffer
|
|||||||
*@Required()
|
*@Required()
|
||||||
*/
|
*/
|
||||||
public $buf_name;
|
public $buf_name;
|
||||||
/** @var string|null $sub_folder */
|
/** @var string $sub_folder */
|
||||||
public $sub_folder = null;
|
public $sub_folder = null;
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
namespace ZM\Event\Swoole;
|
namespace ZM\Event\Swoole;
|
||||||
|
|
||||||
|
|
||||||
|
use Co;
|
||||||
use Doctrine\Common\Annotations\AnnotationException;
|
use Doctrine\Common\Annotations\AnnotationException;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
@@ -48,6 +49,21 @@ class WorkerStartEvent implements SwooleEvent
|
|||||||
|
|
||||||
//设置炸毛buf中储存的对象
|
//设置炸毛buf中储存的对象
|
||||||
ZMBuf::$globals = new GlobalConfig();
|
ZMBuf::$globals = new GlobalConfig();
|
||||||
|
ZMBuf::$config = [];
|
||||||
|
$file = scandir(WORKING_DIR . '/config/');
|
||||||
|
unset($file[0], $file[1]);
|
||||||
|
foreach ($file as $k => $v) {
|
||||||
|
if ($v == "global.php") continue;
|
||||||
|
$name = explode(".", $v);
|
||||||
|
if (($prefix = end($name)) == "json") {
|
||||||
|
ZMBuf::$config[$name[0]] = json_decode(Co::readFile(WORKING_DIR . '/config/' . $v), true);
|
||||||
|
Console::info("已读取配置文件(json):" . $prefix);
|
||||||
|
} elseif ($prefix == "php") {
|
||||||
|
ZMBuf::$config[$name[0]] = include_once WORKING_DIR . '/config/' . $v;
|
||||||
|
if (is_array(ZMBuf::$config[$name[0]]))
|
||||||
|
Console::info("已读取配置文件(php):" . $prefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (ZMBuf::globals("sql_config")["sql_host"] != "") {
|
if (ZMBuf::globals("sql_config")["sql_host"] != "") {
|
||||||
Console::info("新建SQL连接池中");
|
Console::info("新建SQL连接池中");
|
||||||
ZMBuf::$sql_pool = new SQLPool();
|
ZMBuf::$sql_pool = new SQLPool();
|
||||||
@@ -113,7 +129,6 @@ class WorkerStartEvent implements SwooleEvent
|
|||||||
|
|
||||||
//加载composer类
|
//加载composer类
|
||||||
Console::info("加载composer资源中");
|
Console::info("加载composer资源中");
|
||||||
/** @noinspection PhpIncludeInspection */
|
|
||||||
require_once WORKING_DIR . "/vendor/autoload.php";
|
require_once WORKING_DIR . "/vendor/autoload.php";
|
||||||
|
|
||||||
//加载各个模块的注解类,以及反射
|
//加载各个模块的注解类,以及反射
|
||||||
@@ -126,7 +141,7 @@ class WorkerStartEvent implements SwooleEvent
|
|||||||
|
|
||||||
private function setAutosaveTimer($globals) {
|
private function setAutosaveTimer($globals) {
|
||||||
DataProvider::$buffer_list = [];
|
DataProvider::$buffer_list = [];
|
||||||
Timer::tick($globals * 1000, function() {
|
Timer::tick($globals * 1000, function () {
|
||||||
DataProvider::saveBuffer();
|
DataProvider::saveBuffer();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user