From fa2bfe31b128adb6e155be1b8efee8bc5a6dab15 Mon Sep 17 00:00:00 2001 From: Lkeme <19500576+lkeme@users.noreply.github.com> Date: Sat, 4 Jun 2022 16:08:00 +0800 Subject: [PATCH] [feat] print plugins ascii table --- plugin/CheckUpdate/CheckUpdate.php | 2 -- plugin/Login/Login.php | 2 -- src/Plugin/Plugin.php | 25 ++++++++++++++++++++++--- src/Util/AsciiTable/AsciiTable.php | 1 - 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/plugin/CheckUpdate/CheckUpdate.php b/plugin/CheckUpdate/CheckUpdate.php index 96e5774..ac309d2 100644 --- a/plugin/CheckUpdate/CheckUpdate.php +++ b/plugin/CheckUpdate/CheckUpdate.php @@ -49,8 +49,6 @@ class CheckUpdate extends BasePluginRW TimeLock::initTimeLock(); // Cache::initCache(); - // - Log::info('加载CheckUpdate插件'); // $this::class $plugin->register($this, 'execute'); } diff --git a/plugin/Login/Login.php b/plugin/Login/Login.php index f71c54e..ed21c48 100644 --- a/plugin/Login/Login.php +++ b/plugin/Login/Login.php @@ -62,8 +62,6 @@ class Login extends BasePlugin TimeLock::initTimeLock(); // Cache::initCache(); - // - Log::info('加载Login插件'); // $this::class $plugin->register($this, 'execute'); } diff --git a/src/Plugin/Plugin.php b/src/Plugin/Plugin.php index 1aad81e..8062e83 100644 --- a/src/Plugin/Plugin.php +++ b/src/Plugin/Plugin.php @@ -17,6 +17,8 @@ namespace Bhp\Plugin; +use Bhp\Log\Log; +use Bhp\Util\AsciiTable\AsciiTable; use Bhp\Util\DesignPattern\SingleTon; class Plugin extends SingleTon @@ -125,7 +127,7 @@ class Plugin extends SingleTon */ protected function addPluginInfo(string $hook, array $info): void { - $this->validatePlugins($hook, $info); + $info = $this->validatePlugins($hook, $info); // $this->_plugins[$hook] = $info; $this->_priority[] = $info['priority']; @@ -134,9 +136,9 @@ class Plugin extends SingleTon /** * @param string $hook * @param array $info - * @return void + * @return array */ - protected function validatePlugins(string $hook, array $info): void + protected function validatePlugins(string $hook, array $info): array { // 插件信息缺失 $fillable = ['hook', 'name', 'version', 'desc', 'priority', 'cycle']; @@ -157,6 +159,10 @@ class Plugin extends SingleTon if ($info['priority'] < 1000) { failExit("加载 $hook 插件错误,插件优先级定义错误,请检查修正."); } + // + $info['status'] = '√'; + // + return $info; } /** @@ -222,4 +228,17 @@ class Plugin extends SingleTon array_multisort($arr, $sort_order, $this->_plugins); } + + /** + * @return void + */ + protected function preloadPlugins(): void + { + $th_list = AsciiTable::array2table($this->_plugins, '预加载插件列表'); + foreach ($th_list as $item) { + // Log::info($item); + echo $item . PHP_EOL; + } + } + } \ No newline at end of file diff --git a/src/Util/AsciiTable/AsciiTable.php b/src/Util/AsciiTable/AsciiTable.php index ce51472..8d815d0 100644 --- a/src/Util/AsciiTable/AsciiTable.php +++ b/src/Util/AsciiTable/AsciiTable.php @@ -364,7 +364,6 @@ class AsciiTable // foreach (explode("\r\n", $builder->renderTable()) as $value) { if ($value) { - echo $value.PHP_EOL; $th_list[] = $value; } }