update plugin docs and add some helper functions

This commit is contained in:
Jerry
2023-03-31 21:44:48 +08:00
committed by GitHub
parent f85719ac8b
commit baa6ce9fc1
10 changed files with 161 additions and 12 deletions

View File

@@ -18,12 +18,14 @@ use ZM\Framework;
use ZM\Logger\ConsoleLogger;
use ZM\Middleware\MiddlewareHandler;
use ZM\Plugin\OneBot\BotMap;
use ZM\Plugin\ZMPlugin;
use ZM\Schedule\Timer;
use ZM\Store\Database\DBException;
use ZM\Store\Database\DBQueryBuilder;
use ZM\Store\Database\DBWrapper;
use ZM\Store\KV\KVInterface;
use ZM\Store\KV\Redis\RedisWrapper;
use ZM\ZMApplication;
// 防止重复引用引发报错
if (function_exists('zm_internal_errcode')) {
@@ -345,3 +347,19 @@ function ws_socket(int $flag = 1): WSServerSocketBase
}
return $a;
}
/**
* 创建炸毛框架应用
*/
function zm_create_app(): ZMApplication
{
return new ZMApplication();
}
/**
* 创建炸毛框架的插件对象
*/
function zm_create_plugin(): ZMPlugin
{
return new ZMPlugin();
}

View File

@@ -50,7 +50,7 @@ class Framework
public const VERSION_ID = 712;
/** @var string 版本名称 */
public const VERSION = '3.1.7';
public const VERSION = '3.1.8';
/**
* @var RuntimePreferences 运行时偏好(环境信息&参数)

View File

@@ -53,7 +53,7 @@ class PluginManager
continue;
}
// 先看有没有 zmplugin.json没有则不是正常的插件发个 notice 然后跳过
// 先看有没有 composer.json没有则不是正常的插件发个 notice 然后跳过
$meta_file = $item . '/composer.json';
if (!is_file($meta_file)) {
logger()->notice('插件目录 {dir} 没有插件元信息composer.json跳过扫描。', ['dir' => $item]);
@@ -382,7 +382,7 @@ class PluginManager
++$file_added;
}
// 找有没有 main没有 main 就不添加 stub
$main = (json_decode(file_get_contents($dir . '/zmplugin.json'), true)['main'] ?? 'main.php');
$main = (json_decode(file_get_contents($dir . '/composer.json'), true)['extra']['zm-plugin-main'] ?? 'main.php');
if (file_exists(zm_dir($dir . '/' . $main)) && $phar->offsetExists($main)) {
$command_context?->info('设置插件默认入口文件 ' . $main);
$phar->setStub($phar->setDefaultStub($main));

View File

@@ -7,7 +7,7 @@ namespace ZM\Plugin;
use ZM\Exception\PluginException;
/**
* 插件的元信息对象,对应 zmplugin.json
* 插件的元信息对象
*/
class PluginMeta implements \JsonSerializable
{