mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-04 23:35:35 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc7af105f4 | ||
|
|
fd96543268 | ||
|
|
cebc6fb310 | ||
|
|
c654cf40d5 | ||
|
|
68cc536af3 | ||
|
|
42412fee98 | ||
|
|
500ec4707e | ||
|
|
b09857e3b8 | ||
|
|
7d79126c8f | ||
|
|
a542558503 | ||
|
|
6697591a22 |
@@ -2,7 +2,7 @@
|
||||
|
||||
[]()
|
||||
[](https://github.com/zhamao-robot/zhamao-framework/blob/master/LICENSE)
|
||||
[]()
|
||||
[](https://packagist.org/packages/zhamao/framework)
|
||||
|
||||
[](https://github.com/zhamao-robot/zhamao-framework/search?q=stupid)
|
||||
[](https://github.com/zhamao-robot/zhamao-framework/search?q=TODO)
|
||||
|
||||
66
bin/start
66
bin/start
@@ -40,6 +40,71 @@ switch ($argv[1] ?? '') {
|
||||
array_shift($argv);
|
||||
require_once 'systemd';
|
||||
break;
|
||||
case 'init':
|
||||
array_shift($argv);
|
||||
if (LOAD_MODE != 1) {
|
||||
echo "initialization must be started with composer-project mode!\n";
|
||||
exit(1);
|
||||
}
|
||||
$cwd = LOAD_MODE_COMPOSER_PATH;
|
||||
echo "Copying default module file ...";
|
||||
@mkdir($cwd . "/config");
|
||||
@mkdir($cwd . "/src");
|
||||
@mkdir($cwd . "/src/Custom");
|
||||
@mkdir($cwd . "/src/Module");
|
||||
@mkdir($cwd . "/src/Module/Example");
|
||||
@mkdir($cwd . "/src/Module/Middleware");
|
||||
$ls = [
|
||||
"/config/global.php",
|
||||
"/.gitignore",
|
||||
"/config/file_header.json",
|
||||
"/config/motd.txt",
|
||||
"/src/Module/Example/Hello.php",
|
||||
"/src/Module/Middleware/TimerMiddleware.php",
|
||||
"/src/Custom/global_function.php"
|
||||
];
|
||||
foreach($ls as $v) {
|
||||
if(!file_exists($cwd.$v)) {
|
||||
echo "Copying ".$v.PHP_EOL;
|
||||
copy($cwd."/vendor/zhamao/framework".$v, $cwd.$v);
|
||||
}
|
||||
}
|
||||
$autoload = [
|
||||
"psr-4" => [
|
||||
"Module\\" => "src/Module",
|
||||
"Custom\\" => "src/Custom"
|
||||
],
|
||||
"files" => [
|
||||
"src/Custom/global_function.php"
|
||||
]
|
||||
];
|
||||
$scripts = [
|
||||
"server" => "vendor/bin/start server",
|
||||
"server:log-debug" => "vendor/bin/start server --log-debug",
|
||||
"server:log-verbose" => "vendor/bin/start server --log-verbose",
|
||||
"server:log-info" => "vendor/bin/start server --log-info",
|
||||
"server:log-warning" => "vendor/bin/start server --log-warning",
|
||||
"server:debug-mode" => "vendor/bin/start server --debug-mode",
|
||||
"systemd" => "vendor/bin/start systemd"
|
||||
];
|
||||
echo PHP_EOL;
|
||||
if (file_exists($cwd . "/composer.json")) {
|
||||
echo "Updating composer.json ...";
|
||||
$composer = json_decode(file_get_contents($cwd . "/composer.json"), true);
|
||||
if (!isset($composer["autoload"])) {
|
||||
$composer["autoload"] = $autoload;
|
||||
}
|
||||
if (!isset($composer["scripts"])) {
|
||||
$composer["scripts"] = $scripts;
|
||||
}
|
||||
file_put_contents($cwd . "/composer.json", json_encode($composer, 64 | 128 | 256));
|
||||
echo PHP_EOL;
|
||||
} else {
|
||||
echo("Error occurred. Please check your updates.\n");
|
||||
exit(1);
|
||||
}
|
||||
echo "success!\n";
|
||||
break;
|
||||
case '':
|
||||
case 'framework':
|
||||
case 'server':
|
||||
@@ -60,6 +125,7 @@ switch ($argv[1] ?? '') {
|
||||
echo "\n\n -h, --help\t\tShow this help menu";
|
||||
echo "\n framework, server\tstart main framework, this is default option";
|
||||
echo "\n phar-build\t\tbuild a new phar archive";
|
||||
echo "\n init\t\t\tinitialize framework structure in this directory";
|
||||
echo "\n systemd\t\tgenerate a new systemd \".service\" file to use\n\n";
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"description": "High performance QQ robot and web server development framework",
|
||||
"minimum-stability": "stable",
|
||||
"license": "Apache-2.0",
|
||||
"version": "1.5.4",
|
||||
"version": "1.5.6",
|
||||
"authors": [
|
||||
{
|
||||
"name": "whale",
|
||||
|
||||
@@ -43,7 +43,8 @@ $config['sql_config'] = [
|
||||
PDO::ATTR_STRINGIFY_FETCHES => false,
|
||||
PDO::ATTR_EMULATE_PREPARES => false
|
||||
],
|
||||
'sql_no_exception' => false
|
||||
'sql_no_exception' => false,
|
||||
'sql_default_fetch_mode' => PDO::FETCH_BOTH // added in 1.5.6
|
||||
];
|
||||
|
||||
/** CQHTTP连接约定的token */
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
<?php
|
||||
|
||||
//这里写你的全局函数
|
||||
|
||||
function phptest(){
|
||||
echo "Nothing.\n";
|
||||
}
|
||||
@@ -151,6 +151,7 @@ class FrameworkLoader
|
||||
define("ZM_MATCH_NUMBER", 2);
|
||||
define("ZM_MATCH_SECOND", 3);
|
||||
define("ZM_BREAKPOINT", 'if(in_array("--debug-mode", \Framework\FrameworkLoader::$argv)) extract(\Psy\debug(get_defined_vars(), isset($this) ? $this : @get_called_class()));');
|
||||
define("ZM_DEFAULT_FETCH_MODE", self::$settings->get("sql_config")["sql_default_fetch_mode"] ?? 4);
|
||||
}
|
||||
|
||||
private function selfCheck() {
|
||||
|
||||
@@ -28,6 +28,15 @@ class Hello
|
||||
Console::info("机器人 " . $conn->getQQ() . " 已连接!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 在机器人连接后向终端输出信息
|
||||
* @SwooleEventAt("close",rule="connectType:qq")
|
||||
*/
|
||||
public function onDisconnect() {
|
||||
$conn = ctx()->getConnection();
|
||||
Console::info("机器人 " . $conn->getQQ() . " 已断开连接!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 向机器人发送"你好",即可回复这句话
|
||||
* @CQCommand(match="你好",alias={"你好啊","你是谁"})
|
||||
|
||||
@@ -110,7 +110,7 @@ class AnnotationParser
|
||||
foreach ($method_annotations as $vss) {
|
||||
if ($vss instanceof Rule) $vss = self::registerRuleEvent($vss, $vs, $reflection_class);
|
||||
else $vss = self::registerMethod($vss, $vs, $reflection_class);
|
||||
|
||||
Console::debug("寻找 ".$vs->getName() ." -> ".get_class($vss));
|
||||
if ($vss instanceof SwooleEventAt) ZMBuf::$events[SwooleEventAt::class][] = $vss;
|
||||
elseif ($vss instanceof SwooleEventAfter) ZMBuf::$events[SwooleEventAfter::class][] = $vss;
|
||||
elseif ($vss instanceof CQMessage) ZMBuf::$events[CQMessage::class][] = $vss;
|
||||
@@ -326,6 +326,7 @@ class AnnotationParser
|
||||
$class = getAllClasses(DataProvider::getWorkingDir() . "/src/Custom/Annotation/", "Custom\\Annotation");
|
||||
foreach ($class as $v) {
|
||||
$s = DataProvider::getWorkingDir() . '/src/' . str_replace("\\", "/", $v) . ".php";
|
||||
Console::debug("Requiring custom annotation ".$s);
|
||||
require_once $s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,14 @@ class CQCommand extends AnnotationBase implements Level
|
||||
public $regexMatch = "";
|
||||
/** @var string[] */
|
||||
public $alias = [];
|
||||
/** @var string */
|
||||
public $message_type = "";
|
||||
/** @var int */
|
||||
public $user_id = 0;
|
||||
/** @var int */
|
||||
public $group_id = 0;
|
||||
/** @var int */
|
||||
public $discuss_id = 0;
|
||||
/** @var int */
|
||||
public $level = 20;
|
||||
|
||||
|
||||
@@ -90,10 +90,11 @@ class DB
|
||||
/**
|
||||
* @param string $line
|
||||
* @param array $params
|
||||
* @param int $fetch_mode
|
||||
* @return mixed
|
||||
* @throws DbException
|
||||
*/
|
||||
public static function rawQuery(string $line, $params = []) {
|
||||
public static function rawQuery(string $line, $params = [], $fetch_mode = ZM_DEFAULT_FETCH_MODE) {
|
||||
if (ZMBuf::get("sql_log") === true) {
|
||||
$starttime = microtime(true);
|
||||
}
|
||||
@@ -131,7 +132,7 @@ class DB
|
||||
"] " . $line . " " . json_encode($params, JSON_UNESCAPED_UNICODE) . "\n";
|
||||
Coroutine::writeFile(CRASH_DIR . "sql.log", $log, FILE_APPEND);
|
||||
}
|
||||
return $ps->fetchAll();
|
||||
return $ps->fetchAll($fetch_mode);
|
||||
}
|
||||
} catch (DbException $e) {
|
||||
if (ZMBuf::get("sql_log") === true) {
|
||||
|
||||
@@ -41,10 +41,11 @@ class SelectBody
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $fetch_mode
|
||||
* @return null
|
||||
* @throws DbException
|
||||
*/
|
||||
public function fetchAll() {
|
||||
public function fetchAll($fetch_mode = ZM_DEFAULT_FETCH_MODE) {
|
||||
if ($this->table->isCacheEnabled()) {
|
||||
$rr = md5(implode(",", $this->select_thing) . serialize($this->where_thing));
|
||||
if (array_key_exists($rr, $this->table->cache)) {
|
||||
@@ -52,7 +53,7 @@ class SelectBody
|
||||
return $this->table->cache[$rr]->getResult();
|
||||
}
|
||||
}
|
||||
$this->execute();
|
||||
$this->execute($fetch_mode);
|
||||
if ($this->table->isCacheEnabled() && !in_array($rr, $this->table->cache)) {
|
||||
$this->table->cache[$rr] = $this;
|
||||
}
|
||||
@@ -81,11 +82,12 @@ class SelectBody
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $fetch_mode
|
||||
* @throws DbException
|
||||
*/
|
||||
public function execute() {
|
||||
public function execute($fetch_mode = ZM_DEFAULT_FETCH_MODE) {
|
||||
$str = $this->queryPrepare();
|
||||
$this->result = DB::rawQuery($str[0], $str[1]);
|
||||
$this->result = DB::rawQuery($str[0], $str[1], $fetch_mode);
|
||||
}
|
||||
|
||||
public function getResult() { return $this->result; }
|
||||
|
||||
@@ -101,7 +101,11 @@ class MessageEvent
|
||||
foreach (ZMBuf::$events[CQCommand::class] ?? [] as $v) {
|
||||
/** @var CQCommand $v */
|
||||
if ($v->match == "" && $v->regexMatch == "") continue;
|
||||
else {
|
||||
elseif (($v->user_id == 0 || ($v->user_id != 0 && $v->user_id == context()->getData()["user_id"])) &&
|
||||
($v->group_id == 0 || ($v->group_id != 0 && $v->group_id == (context()->getData()["group_id"] ?? 0))) &&
|
||||
($v->discuss_id == 0 || ($v->discuss_id != 0 && $v->discuss_id == (context()->getData()["discuss_id"] ?? 0))) &&
|
||||
($v->message_type == '' || ($v->message_type != '' && $v->message_type == context()->getData()["message_type"]))
|
||||
) {
|
||||
$c = $v->class;
|
||||
$class_construct = [
|
||||
"data" => context()->getData(),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
namespace ZM\Event\Swoole;
|
||||
|
||||
|
||||
use Closure;
|
||||
use Doctrine\Common\Annotations\AnnotationException;
|
||||
use Framework\ZMBuf;
|
||||
use Swoole\Server;
|
||||
@@ -11,8 +12,6 @@ use ZM\Annotation\Swoole\SwooleEventAfter;
|
||||
use ZM\Annotation\Swoole\SwooleEventAt;
|
||||
use ZM\Connection\ConnectionManager;
|
||||
use ZM\Event\EventHandler;
|
||||
use ZM\ModBase;
|
||||
use ZM\ModHandleType;
|
||||
use ZM\Utils\ZMUtil;
|
||||
|
||||
class WSCloseEvent implements SwooleEvent
|
||||
@@ -32,8 +31,7 @@ class WSCloseEvent implements SwooleEvent
|
||||
*/
|
||||
public function onActivate() {
|
||||
ZMUtil::checkWait();
|
||||
ConnectionManager::close($this->fd);
|
||||
set_coroutine_params(["server" => $this->server, "fd" => $this->fd]);
|
||||
set_coroutine_params(["server" => $this->server, "fd" => $this->fd, "connection" => ConnectionManager::get($this->fd)]);
|
||||
foreach(ZMBuf::$events[SwooleEventAt::class] ?? [] as $v) {
|
||||
if(strtolower($v->type) == "close" && $this->parseSwooleRule($v)) {
|
||||
$c = $v->class;
|
||||
@@ -41,6 +39,7 @@ class WSCloseEvent implements SwooleEvent
|
||||
if(context()->getCache("block_continue") === true) break;
|
||||
}
|
||||
}
|
||||
ConnectionManager::close($this->fd);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -60,6 +59,11 @@ class WSCloseEvent implements SwooleEvent
|
||||
}
|
||||
|
||||
private function parseSwooleRule($v) {
|
||||
switch (explode(":", $v->rule)[0]) {
|
||||
case "connectType": //websocket连接类型
|
||||
if ($v->callback instanceof Closure) return call_user_func($v->callback, ConnectionManager::get($this->fd));
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,13 +176,8 @@ class WorkerStartEvent implements SwooleEvent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//加载composer类
|
||||
Console::info("加载composer资源中");
|
||||
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";
|
||||
//remove stupid duplicate code
|
||||
|
||||
//加载各个模块的注解类,以及反射
|
||||
Console::info("检索Module中");
|
||||
|
||||
@@ -15,6 +15,11 @@ use ZM\Http\Response;
|
||||
use Swoole\WebSocket\Frame;
|
||||
use Swoole\WebSocket\Server;
|
||||
|
||||
/**
|
||||
* Class ModBase
|
||||
* @package ZM
|
||||
* @deprecated
|
||||
*/
|
||||
abstract class ModBase
|
||||
{
|
||||
/** @var Server */
|
||||
|
||||
Reference in New Issue
Block a user