mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-21 07:35:34 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aad28f1ec4 | ||
|
|
f1949b1bd0 | ||
|
|
3b8aac5d8f | ||
|
|
5fd45c2542 | ||
|
|
af89c1b1f6 |
@@ -3,7 +3,7 @@
|
|||||||
"description": "High performance QQ robot and web server development framework",
|
"description": "High performance QQ robot and web server development framework",
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"version": "1.5.3",
|
"version": "1.5.4",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "whale",
|
"name": "whale",
|
||||||
@@ -23,11 +23,19 @@
|
|||||||
"swoole/ide-helper": "@dev",
|
"swoole/ide-helper": "@dev",
|
||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
"swlib/saber": "^1.0",
|
"swlib/saber": "^1.0",
|
||||||
"doctrine/annotations": "<1.10.2",
|
"doctrine/annotations": "~1.10",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"ext-posix": "*",
|
"ext-posix": "*",
|
||||||
"ext-ctype": "*",
|
"ext-ctype": "*",
|
||||||
"ext-pdo": "*",
|
"ext-pdo": "*",
|
||||||
"psy/psysh": "@stable"
|
"psy/psysh": "@stable"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Custom\\": "src/Custom",
|
||||||
|
"Framework\\": "src/Framework",
|
||||||
|
"ZM\\": "src/ZM",
|
||||||
|
"Module\\": "src/Module"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,12 @@ $config['sql_config'] = [
|
|||||||
'sql_database' => 'db_name',
|
'sql_database' => 'db_name',
|
||||||
'sql_password' => '',
|
'sql_password' => '',
|
||||||
'sql_enable_cache' => true,
|
'sql_enable_cache' => true,
|
||||||
'sql_reset_cache' => '0300'
|
'sql_reset_cache' => '0300',
|
||||||
|
'sql_options' => [
|
||||||
|
PDO::ATTR_STRINGIFY_FETCHES => false,
|
||||||
|
PDO::ATTR_EMULATE_PREPARES => false
|
||||||
|
],
|
||||||
|
'sql_no_exception' => false
|
||||||
];
|
];
|
||||||
|
|
||||||
/** CQHTTP连接约定的token */
|
/** CQHTTP连接约定的token */
|
||||||
|
|||||||
@@ -43,9 +43,19 @@ class FrameworkLoader
|
|||||||
|
|
||||||
$this->requireGlobalFunctions();
|
$this->requireGlobalFunctions();
|
||||||
if (LOAD_MODE == 0) define("WORKING_DIR", getcwd());
|
if (LOAD_MODE == 0) define("WORKING_DIR", getcwd());
|
||||||
elseif(LOAD_MODE == 1) define("WORKING_DIR", realpath(__DIR__ . "/../../"));
|
elseif (LOAD_MODE == 1) define("WORKING_DIR", realpath(__DIR__ . "/../../"));
|
||||||
elseif (LOAD_MODE == 2) echo "Phar mode: " . WORKING_DIR . PHP_EOL;
|
elseif (LOAD_MODE == 2) echo "Phar mode: " . WORKING_DIR . PHP_EOL;
|
||||||
$this->registerAutoloader('classLoader');
|
//$this->registerAutoloader('classLoader');
|
||||||
|
require_once "DataProvider.php";
|
||||||
|
if (file_exists(DataProvider::getWorkingDir() . "/vendor/autoload.php")) {
|
||||||
|
require_once DataProvider::getWorkingDir() . "/vendor/autoload.php";
|
||||||
|
}
|
||||||
|
if (LOAD_MODE == 2) {
|
||||||
|
require_once FRAMEWORK_DIR . "/vendor/autoload.php";
|
||||||
|
spl_autoload_register('phar_classloader');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
self::$settings = new GlobalConfig();
|
self::$settings = new GlobalConfig();
|
||||||
if (self::$settings->get("debug_mode") === true) {
|
if (self::$settings->get("debug_mode") === true) {
|
||||||
$args[] = "--debug-mode";
|
$args[] = "--debug-mode";
|
||||||
@@ -130,7 +140,7 @@ class FrameworkLoader
|
|||||||
private function defineProperties() {
|
private function defineProperties() {
|
||||||
define("ZM_START_TIME", microtime(true));
|
define("ZM_START_TIME", microtime(true));
|
||||||
define("ZM_DATA", self::$settings->get("zm_data"));
|
define("ZM_DATA", self::$settings->get("zm_data"));
|
||||||
define("ZM_VERSION", json_decode(file_get_contents(__DIR__."/../../composer.json"), true)["version"] ?? "unknown");
|
define("ZM_VERSION", json_decode(file_get_contents(__DIR__ . "/../../composer.json"), true)["version"] ?? "unknown");
|
||||||
define("CONFIG_DIR", self::$settings->get("config_dir"));
|
define("CONFIG_DIR", self::$settings->get("config_dir"));
|
||||||
define("CRASH_DIR", self::$settings->get("crash_dir"));
|
define("CRASH_DIR", self::$settings->get("crash_dir"));
|
||||||
@mkdir(ZM_DATA);
|
@mkdir(ZM_DATA);
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ use ZM\Context\ContextInterface;
|
|||||||
use ZM\Utils\ZMUtil;
|
use ZM\Utils\ZMUtil;
|
||||||
|
|
||||||
|
|
||||||
function classLoader($p) {
|
function phar_classloader($p){
|
||||||
$filepath = getClassPath($p);
|
$filepath = getClassPath($p);
|
||||||
if ($filepath === null)
|
if($filepath === null) {
|
||||||
echo "F:Warning: get class path wrongs.$p\n";
|
Console::debug("F:Warning: get class path wrongs.$p");
|
||||||
//else echo "F:DBG: Found " . $p . "\n";
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
require_once $filepath;
|
require_once $filepath;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class Hello
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 向机器人发送"你好",即可回复这句话
|
* 向机器人发送"你好",即可回复这句话
|
||||||
* @CQCommand("你好")
|
* @CQCommand(match="你好",alias={"你好啊","你是谁"})
|
||||||
*/
|
*/
|
||||||
public function hello() {
|
public function hello() {
|
||||||
return "你好啊,我是由炸毛框架构建的机器人!";
|
return "你好啊,我是由炸毛框架构建的机器人!";
|
||||||
@@ -66,7 +66,6 @@ class Hello
|
|||||||
* @Middleware("timer")
|
* @Middleware("timer")
|
||||||
*/
|
*/
|
||||||
public function timer() {
|
public function timer() {
|
||||||
eval(ZM_BREAKPOINT);
|
|
||||||
return "This page is used as testing TimerMiddleware! Do not use it in production.";
|
return "This page is used as testing TimerMiddleware! Do not use it in production.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ class CQCommand extends AnnotationBase implements Level
|
|||||||
public $match = "";
|
public $match = "";
|
||||||
/** @var string */
|
/** @var string */
|
||||||
public $regexMatch = "";
|
public $regexMatch = "";
|
||||||
|
/** @var string[] */
|
||||||
|
public $alias = [];
|
||||||
/** @var int */
|
/** @var int */
|
||||||
public $level = 20;
|
public $level = 20;
|
||||||
|
|
||||||
@@ -32,4 +34,4 @@ class CQCommand extends AnnotationBase implements Level
|
|||||||
*/
|
*/
|
||||||
public function setLevel(int $level) { $this->level = $level; }
|
public function setLevel(int $level) { $this->level = $level; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait WhereBody
|
|||||||
protected $where_thing = [];
|
protected $where_thing = [];
|
||||||
|
|
||||||
public function where($column, $operation_or_value, $value = null) {
|
public function where($column, $operation_or_value, $value = null) {
|
||||||
if (!in_array($operation_or_value, ['=', '!='])) $this->where_thing['='][$column] = $operation_or_value;
|
if (!in_array($operation_or_value, ['=', '!=', '>', '<', '>=', '<=', 'IN', 'in'])) $this->where_thing['='][$column] = $operation_or_value;
|
||||||
elseif ($value !== null) $this->where_thing[$operation_or_value][$column] = $value;
|
elseif ($value !== null) $this->where_thing[$operation_or_value][$column] = $value;
|
||||||
else $this->where_thing['='][$column] = $operation_or_value;
|
else $this->where_thing['='][$column] = $operation_or_value;
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class MessageEvent
|
|||||||
public function onBefore() {
|
public function onBefore() {
|
||||||
$obj_list = ZMBuf::$events[CQBefore::class]["message"] ?? [];
|
$obj_list = ZMBuf::$events[CQBefore::class]["message"] ?? [];
|
||||||
foreach ($obj_list as $v) {
|
foreach ($obj_list as $v) {
|
||||||
if($v->level < 200) break;
|
if ($v->level < 200) break;
|
||||||
EventHandler::callWithMiddleware(
|
EventHandler::callWithMiddleware(
|
||||||
$v->class,
|
$v->class,
|
||||||
$v->method,
|
$v->method,
|
||||||
@@ -65,7 +65,7 @@ class MessageEvent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (ZMBuf::$events[CQBefore::class]["message"] ?? [] as $v) {
|
foreach (ZMBuf::$events[CQBefore::class]["message"] ?? [] as $v) {
|
||||||
if($v->level >= 200) continue;
|
if ($v->level >= 200) continue;
|
||||||
$c = $v->class;
|
$c = $v->class;
|
||||||
if (ctx()->getCache("level") != 0) continue;
|
if (ctx()->getCache("level") != 0) continue;
|
||||||
EventHandler::callWithMiddleware(
|
EventHandler::callWithMiddleware(
|
||||||
@@ -117,6 +117,13 @@ class MessageEvent
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
} elseif (in_array($word[0], $v->alias)) {
|
||||||
|
Console::debug("Calling $c -> {$v->method}");
|
||||||
|
$this->function_call = EventHandler::callWithMiddleware($obj[$c], $v->method, $class_construct, [$word], function ($r) {
|
||||||
|
if (is_string($r)) context()->reply($r);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
return;
|
||||||
} elseif ($v->regexMatch != "" && ($args = matchArgs($v->regexMatch, context()->getMessage())) !== false) {
|
} elseif ($v->regexMatch != "" && ($args = matchArgs($v->regexMatch, context()->getMessage())) !== false) {
|
||||||
Console::debug("Calling $c -> {$v->method}");
|
Console::debug("Calling $c -> {$v->method}");
|
||||||
$this->function_call = EventHandler::callWithMiddleware($obj[$c], $v->method, $class_construct, [$args], function ($r) {
|
$this->function_call = EventHandler::callWithMiddleware($obj[$c], $v->method, $class_construct, [$args], function ($r) {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class EventHandler
|
|||||||
" [" . $param1->getStatusCode() . "] " . $param0->server["request_uri"]
|
" [" . $param1->getStatusCode() . "] " . $param0->server["request_uri"]
|
||||||
);
|
);
|
||||||
if (!$param1->isEnd()) $param1->end("Internal server error: " . $e->getMessage());
|
if (!$param1->isEnd()) $param1->end("Internal server error: " . $e->getMessage());
|
||||||
Console::error("Internal server error (500), caused by uncaught exception.");
|
Console::error("Internal server exception (500), caused by ".get_class($e));
|
||||||
Console::log($e->getTraceAsString(), "gray");
|
Console::log($e->getTraceAsString(), "gray");
|
||||||
} catch (Error $e) {
|
} catch (Error $e) {
|
||||||
/** @var Response $param1 */
|
/** @var Response $param1 */
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class RequestEvent implements SwooleEvent
|
|||||||
$this->response->setHeader($k, $v);
|
$this->response->setHeader($k, $v);
|
||||||
}
|
}
|
||||||
$uri = $this->request->server["request_uri"];
|
$uri = $this->request->server["request_uri"];
|
||||||
Console::verbose($this->request->server["remote_addr"]." request ".$uri);
|
Console::verbose($this->request->server["remote_addr"] . " request " . $uri);
|
||||||
$uri = explode("/", $uri);
|
$uri = explode("/", $uri);
|
||||||
$uri = array_diff($uri, ["..", "", "."]);
|
$uri = array_diff($uri, ["..", "", "."]);
|
||||||
$node = ZMBuf::$req_mapping;
|
$node = ZMBuf::$req_mapping;
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ class WorkerStartEvent implements SwooleEvent
|
|||||||
->withCharset('utf8mb4')
|
->withCharset('utf8mb4')
|
||||||
->withUsername($sql["sql_username"])
|
->withUsername($sql["sql_username"])
|
||||||
->withPassword($sql["sql_password"])
|
->withPassword($sql["sql_password"])
|
||||||
->withOptions([PDO::ATTR_STRINGIFY_FETCHES => false])
|
->withOptions($sql["sql_options"] ?? [PDO::ATTR_STRINGIFY_FETCHES => false])
|
||||||
);
|
);
|
||||||
DB::initTableList();
|
DB::initTableList();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user