diff --git a/src/Globals/global_class_alias.php b/src/Globals/global_class_alias.php index ad21884a..9f4d1a1c 100644 --- a/src/Globals/global_class_alias.php +++ b/src/Globals/global_class_alias.php @@ -12,4 +12,4 @@ class_alias(\ZM\Annotation\OneBot\BotCommand::class, 'BotCommand'); class_alias(\ZM\Annotation\OneBot\BotEvent::class, 'BotEvent'); class_alias(\ZM\Annotation\OneBot\CommandArgument::class, 'CommandArgument'); class_alias(\ZM\Annotation\Closed::class, 'Closed'); -class_alias(\ZM\Plugin\InstantPlugin::class, 'InstantPlugin'); +class_alias(\ZM\Plugin\ZMPlugin::class, 'ZMPlugin'); diff --git a/src/ZM/Plugin/InstantPlugin.php b/src/ZM/Plugin/ZMPlugin.php similarity index 80% rename from src/ZM/Plugin/InstantPlugin.php rename to src/ZM/Plugin/ZMPlugin.php index 9421e2b6..d8a6052b 100644 --- a/src/ZM/Plugin/InstantPlugin.php +++ b/src/ZM/Plugin/ZMPlugin.php @@ -8,22 +8,25 @@ use ZM\Annotation\Http\Route; use ZM\Annotation\OneBot\BotCommand; use ZM\Annotation\OneBot\BotEvent; -class InstantPlugin +/** + * 单文件插件声明类 + */ +class ZMPlugin { /** @var string 插件目录 */ - protected $dir; + protected string $dir; /** @var array 机器人事件列表 */ - protected $bot_events = []; + protected array $bot_events = []; /** @var array 机器人指令列表 */ - protected $bot_commands = []; + protected array $bot_commands = []; /** @var array 全局的事件列表 */ - protected $events = []; + protected array $events = []; /** @var array 注册的路由列表 */ - protected $routes = []; + protected array $routes = []; public function __construct(string $dir) { @@ -45,7 +48,7 @@ class InstantPlugin $this->bot_commands[] = $command; } - public function registerEvent(string $event_name, callable $callback, int $level = 20) + public function addEvent(string $event_name, callable $callback, int $level = 20) { $this->events[] = [$event_name, $callback, $level]; } diff --git a/src/ZM/InstantApplication.php b/src/ZM/ZMApplication.php similarity index 73% rename from src/ZM/InstantApplication.php rename to src/ZM/ZMApplication.php index c6380078..8f805f0a 100644 --- a/src/ZM/InstantApplication.php +++ b/src/ZM/ZMApplication.php @@ -6,12 +6,12 @@ namespace ZM; use ZM\Command\Server\ServerStartCommand; use ZM\Exception\SingletonViolationException; -use ZM\Plugin\InstantPlugin; +use ZM\Plugin\ZMPlugin; -class InstantApplication extends InstantPlugin +class ZMApplication extends ZMPlugin { - /** @var null|InstantApplication 存储单例类的变量 */ - private static ?InstantApplication $obj; + /** @var null|ZMApplication 存储单例类的变量 */ + private static ?ZMApplication $obj; /** @var array 存储要传入的args */ private array $args = []; @@ -26,13 +26,13 @@ class InstantApplication extends InstantPlugin $this->args = ServerStartCommand::exportOptionArray(); } - public function withConfig(array $config): InstantApplication + public function withConfig(array $config): ZMApplication { // TODO: 完成patch config return $this; } - public function withArgs(array $args): InstantApplication + public function withArgs(array $args): ZMApplication { $this->args = array_replace_recursive($this->args, $args); return $this;