mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-04 07:15:36 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41f03fbba4 | ||
|
|
b3089c1bba | ||
|
|
c5a6f1fea4 | ||
|
|
ba2777137b |
@@ -37,11 +37,9 @@
|
||||
"php": "^7.2 || ^7.3 || ^7.4 || ^8.0 || ^8.1",
|
||||
"ext-json": "*",
|
||||
"ext-posix": "*",
|
||||
"doctrine/annotations": "~1.12 || ~1.4.0",
|
||||
"doctrine/dbal": "^2.13.1",
|
||||
"jelix/version": "^2.0",
|
||||
"koriym/attributes": "^1.0",
|
||||
"league/climate": "^3.6",
|
||||
"psy/psysh": "^0.11.2",
|
||||
"symfony/console": "~5.0 || ~4.0 || ~3.0",
|
||||
"symfony/polyfill-ctype": "^1.19",
|
||||
|
||||
@@ -49,20 +49,22 @@ docker run -it --rm -v $(pwd):/app/ -p 20001:20001 zmbot/swoole vendor/bin/start
|
||||
|
||||
```verilog
|
||||
$ vendor/bin/start server
|
||||
host: 0.0.0.0 | port: 20001
|
||||
log_level: 2 | version: 2.0.0
|
||||
config: global.php | worker_num: 4
|
||||
working_dir: /app/zhamao-framework
|
||||
______
|
||||
|__ / |__ __ _ _ __ ___ __ _ ___
|
||||
/ /| '_ \ / _` | '_ ` _ \ / _` |/ _ \
|
||||
/ /_| | | | (_| | | | | | | (_| | (_) |
|
||||
/____|_| |_|\__,_|_| |_| |_|\__,_|\___/
|
||||
=================================================================
|
||||
working_dir: /app/zhamao-framework-starter
|
||||
listen: 0.0.0.0:20001 | worker: 4 (auto)
|
||||
environment: default | log_level: 2
|
||||
version: 2.7.0 | master_pid: 28449
|
||||
=================================================================
|
||||
______
|
||||
|__ / |__ __ _ _ __ ___ __ _ ___
|
||||
/ /| '_ \ / _` | '_ ` _ \ / _` |/ _ \
|
||||
/ /_| | | | (_| | | | | | | (_| | (_) |
|
||||
/____|_| |_|\__,_|_| |_| |_|\__,_|\___/
|
||||
|
||||
[14:27:31] [S] [#3] Worker #3 已启动
|
||||
[14:27:31] [S] [#0] Worker #0 已启动
|
||||
[14:27:31] [S] [#2] Worker #2 已启动
|
||||
[14:27:31] [S] [#1] Worker #1 已启动
|
||||
[03-20 22:30:56] [S] [#1] Worker #1 started
|
||||
[03-20 22:30:56] [S] [#2] Worker #2 started
|
||||
[03-20 22:30:56] [S] [#3] Worker #3 started
|
||||
[03-20 22:30:56] [S] [#0] Worker #0 started
|
||||
```
|
||||
|
||||
单纯运行 炸毛框架 后,如果不部署或安装启动任何机器人客户端的话,仅仅相当于启动了一个 监听 20001 端口的WebSoket + HTTP 服务器。你可以通过浏览器访问:http://127.0.0.1:20001 ,或者你部署到了服务器后需要输入服务器地址。
|
||||
|
||||
@@ -4,6 +4,14 @@
|
||||
|
||||
同时此处将只使用 build 版本号进行区分。
|
||||
|
||||
## build 449 (2022-3-21)
|
||||
|
||||
- 新增 Composer 模块加载和分发模式
|
||||
|
||||
## build 448 (2022-3-20)
|
||||
|
||||
- 加快 build 命令的执行速度,取消进度条和提升性能
|
||||
|
||||
## build 447 (2022-3-20)
|
||||
|
||||
- 发布 2.7.0 正式版
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
# 更新日志(v2 版本)
|
||||
|
||||
## v2.7.2(build 449)
|
||||
|
||||
> 更新时间:2022.3.21
|
||||
|
||||
- 新增 Composer 模块加载和分发模式
|
||||
|
||||
## v2.7.1(build 448)
|
||||
|
||||
> 更新时间:2022.3.20
|
||||
|
||||
- 加快 build 命令的执行速度,取消进度条和提升性能
|
||||
|
||||
## v2.7.0(build 447)
|
||||
|
||||
> 更新时间:2022.3.20
|
||||
|
||||
@@ -24,6 +24,7 @@ use ZM\Console\Console;
|
||||
use ZM\Exception\AnnotationException;
|
||||
use ZM\Utils\Manager\RouteManager;
|
||||
use ZM\Utils\ZMUtil;
|
||||
use function server;
|
||||
|
||||
class AnnotationParser
|
||||
{
|
||||
@@ -211,6 +212,9 @@ class AnnotationParser
|
||||
*/
|
||||
public function addRegisterPath($path, $indoor_name)
|
||||
{
|
||||
if (server()->worker_id === 0) {
|
||||
Console::verbose('Add register path: ' . $path . ' => ' . $indoor_name);
|
||||
}
|
||||
$this->path_list[] = [$path, $indoor_name];
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace ZM\Command;
|
||||
|
||||
use ArrayIterator;
|
||||
use League\CLImate\CLImate;
|
||||
use Phar;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
@@ -66,7 +67,6 @@ class BuildCommand extends Command
|
||||
@unlink($target_dir . $filename);
|
||||
$phar = new Phar($target_dir . $filename);
|
||||
$phar->startBuffering();
|
||||
$climate = new CLImate();
|
||||
|
||||
$all = DataProvider::scanDirFiles(DataProvider::getSourceRootDir(), true, true);
|
||||
|
||||
@@ -76,19 +76,29 @@ class BuildCommand extends Command
|
||||
});
|
||||
|
||||
sort($all);
|
||||
$progress = $climate->progress()->total(count($all));
|
||||
|
||||
$archive_dir = DataProvider::getSourceRootDir();
|
||||
foreach ($all as $k => $v) {
|
||||
$phar->addFile($archive_dir . '/' . $v, $v);
|
||||
$progress->current($k + 1, 'Adding ' . $v);
|
||||
}
|
||||
$map = [];
|
||||
|
||||
if (class_exists('\\League\\CLImate\\CLImate')) {
|
||||
$climate = new CLImate();
|
||||
$progress = $climate->progress()->total(count($all));
|
||||
}
|
||||
foreach ($all as $k => $v) {
|
||||
$map[$v] = $archive_dir . '/' . $v;
|
||||
if (isset($progress)) {
|
||||
$progress->current($k + 1, 'Adding ' . $v);
|
||||
}
|
||||
}
|
||||
$this->output->write('<info>Building...</info>');
|
||||
$phar->buildFromIterator(new ArrayIterator($map));
|
||||
$phar->setStub(
|
||||
"#!/usr/bin/env php\n" .
|
||||
$phar->createDefaultStub(LOAD_MODE == 0 ? 'src/entry.php' : 'vendor/zhamao/framework/src/entry.php')
|
||||
);
|
||||
$phar->stopBuffering();
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln('Successfully built. Location: ' . $target_dir . "{$filename}");
|
||||
$this->output->writeln('<info>You may use `chmod +x server.phar` to let phar executable with `./` command</info>');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,25 @@ class ModuleListCommand extends Command
|
||||
if ($list === []) {
|
||||
echo Console::setColor('没有发现已打包且装载的模块!', 'yellow') . PHP_EOL;
|
||||
}
|
||||
|
||||
$list = ModuleManager::getComposerModules();
|
||||
foreach ($list as $v) {
|
||||
echo '[' . Console::setColor($v['name'], 'blue') . ']' . PHP_EOL;
|
||||
$out_list = ['类型' => 'Composer库(composer)'];
|
||||
$out_list['包名'] = $v['composer-name'];
|
||||
$out_list['目录'] = str_replace(DataProvider::getSourceRootDir() . '/', '', $v['module-path']);
|
||||
if (isset($v['version'])) {
|
||||
$out_list['版本'] = $v['version'];
|
||||
}
|
||||
if (isset($v['description'])) {
|
||||
$out_list['描述'] = $v['description'];
|
||||
}
|
||||
$out_list['命名空间'] = $v['namespace'];
|
||||
$this->printList($out_list);
|
||||
}
|
||||
if ($list === []) {
|
||||
echo Console::setColor('没有发现Composer模块!', 'yellow') . PHP_EOL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ use ZM\Exception\InitException;
|
||||
|
||||
class ConsoleApplication extends Application
|
||||
{
|
||||
public const VERSION_ID = 447;
|
||||
public const VERSION_ID = 449;
|
||||
|
||||
public const VERSION = '2.7.0';
|
||||
public const VERSION = '2.7.2';
|
||||
|
||||
private static $obj;
|
||||
|
||||
|
||||
@@ -165,9 +165,6 @@ class OnWorkerStart implements SwooleEvent
|
||||
if (trim($k, '\\') == 'ZM') {
|
||||
continue;
|
||||
}
|
||||
if (\server()->worker_id == 0) {
|
||||
Console::verbose('Add ' . $v . ":{$k} to register path");
|
||||
}
|
||||
$parser->addRegisterPath(DataProvider::getSourceRootDir() . '/' . $v . '/', trim($k, '\\'));
|
||||
}
|
||||
}
|
||||
@@ -187,6 +184,15 @@ class OnWorkerStart implements SwooleEvent
|
||||
}
|
||||
}
|
||||
|
||||
// 检查所有的Composer模块,并加载注解
|
||||
$list = ModuleManager::getComposerModules();
|
||||
foreach ($list as $k => $v) {
|
||||
if (\server()->worker_id === 0) {
|
||||
Console::info('Loading composer module: ' . $k);
|
||||
}
|
||||
$parser->addRegisterPath($v['module-path'], $v['namespace']);
|
||||
}
|
||||
|
||||
$parser->registerMods();
|
||||
EventManager::loadEventByParser($parser); // 加载事件
|
||||
|
||||
|
||||
@@ -111,6 +111,34 @@ class ModuleManager
|
||||
return $modules;
|
||||
}
|
||||
|
||||
public static function getComposerModules()
|
||||
{
|
||||
$vendor_file = DataProvider::getSourceRootDir() . '/vendor/composer/installed.json';
|
||||
$obj = json_decode(file_get_contents($vendor_file), true);
|
||||
if ($obj === null) {
|
||||
return [];
|
||||
}
|
||||
$modules = [];
|
||||
foreach ($obj['packages'] as $v) {
|
||||
if (isset($v['extra']['zm']['module-path'])) {
|
||||
if (is_array($v['extra']['zm']['module-path'])) {
|
||||
foreach ($v['extra']['zm']['module-path'] as $module_path) {
|
||||
$m = self::getComposerModuleInfo($v, $module_path);
|
||||
if ($m !== null) {
|
||||
$modules[$m['name']] = $m;
|
||||
}
|
||||
}
|
||||
} elseif (is_string($v['extra']['zm']['module-path'])) {
|
||||
$m = self::getComposerModuleInfo($v, $v['extra']['zm']['module-path']);
|
||||
if ($m !== null) {
|
||||
$modules[$m['name']] = $m;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* 打包模块
|
||||
* @param $module
|
||||
@@ -152,4 +180,38 @@ class ModuleManager
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static function getComposerModuleInfo($v, $module_path)
|
||||
{
|
||||
$module_root_path = realpath(DataProvider::getSourceRootDir() . '/vendor/composer/' . $v['install-path'] . '/' . $module_path);
|
||||
if ($module_root_path === false) {
|
||||
Console::warning(zm_internal_errcode('E00055') . '无法找到Composer发布的插件配置路径在包 `' . $v['name'] . '` 中!');
|
||||
return null;
|
||||
}
|
||||
$json = json_decode(file_get_contents($module_root_path . '/zm.json'), true);
|
||||
if ($json === null) {
|
||||
Console::warning(zm_internal_errcode('E00054') . 'Composer包内无法正常读取 ' . $v['name'] . ' 的内的配置文件(zm.json)!');
|
||||
return null;
|
||||
}
|
||||
if (!isset($json['name'])) {
|
||||
return null;
|
||||
}
|
||||
$json['composer-name'] = $v['name'];
|
||||
$json['module-root-path'] = realpath(DataProvider::getSourceRootDir() . '/vendor/composer/' . $v['install-path']);
|
||||
$json['module-path'] = realpath($json['module-root-path'] . '/' . $module_path);
|
||||
if (isset($v['autoload']['psr-4'])) {
|
||||
foreach ($v['autoload']['psr-4'] as $ks => $vs) {
|
||||
$vs = trim($vs, '/');
|
||||
if (strpos($module_path, $vs) === 0) {
|
||||
$json['namespace'] = trim($ks . str_replace('/', '\\', trim(substr($module_path, strlen($vs)), '/')), '\\');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isset($json['namespace'])) {
|
||||
Console::warning(zm_internal_errcode('E00055') . '无法获取Composer发布的模块命名空间!');
|
||||
return null;
|
||||
}
|
||||
return $json;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user