[feat] print plugins ascii table

This commit is contained in:
Lkeme 2022-06-04 16:08:00 +08:00
parent d3a046792b
commit fa2bfe31b1
4 changed files with 22 additions and 8 deletions

View File

@ -49,8 +49,6 @@ class CheckUpdate extends BasePluginRW
TimeLock::initTimeLock(); TimeLock::initTimeLock();
// //
Cache::initCache(); Cache::initCache();
//
Log::info('加载CheckUpdate插件');
// $this::class // $this::class
$plugin->register($this, 'execute'); $plugin->register($this, 'execute');
} }

View File

@ -62,8 +62,6 @@ class Login extends BasePlugin
TimeLock::initTimeLock(); TimeLock::initTimeLock();
// //
Cache::initCache(); Cache::initCache();
//
Log::info('加载Login插件');
// $this::class // $this::class
$plugin->register($this, 'execute'); $plugin->register($this, 'execute');
} }

View File

@ -17,6 +17,8 @@
namespace Bhp\Plugin; namespace Bhp\Plugin;
use Bhp\Log\Log;
use Bhp\Util\AsciiTable\AsciiTable;
use Bhp\Util\DesignPattern\SingleTon; use Bhp\Util\DesignPattern\SingleTon;
class Plugin extends SingleTon class Plugin extends SingleTon
@ -125,7 +127,7 @@ class Plugin extends SingleTon
*/ */
protected function addPluginInfo(string $hook, array $info): void protected function addPluginInfo(string $hook, array $info): void
{ {
$this->validatePlugins($hook, $info); $info = $this->validatePlugins($hook, $info);
// //
$this->_plugins[$hook] = $info; $this->_plugins[$hook] = $info;
$this->_priority[] = $info['priority']; $this->_priority[] = $info['priority'];
@ -134,9 +136,9 @@ class Plugin extends SingleTon
/** /**
* @param string $hook * @param string $hook
* @param array $info * @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']; $fillable = ['hook', 'name', 'version', 'desc', 'priority', 'cycle'];
@ -157,6 +159,10 @@ class Plugin extends SingleTon
if ($info['priority'] < 1000) { if ($info['priority'] < 1000) {
failExit("加载 $hook 插件错误,插件优先级定义错误,请检查修正."); failExit("加载 $hook 插件错误,插件优先级定义错误,请检查修正.");
} }
//
$info['status'] = '√';
//
return $info;
} }
/** /**
@ -222,4 +228,17 @@ class Plugin extends SingleTon
array_multisort($arr, $sort_order, $this->_plugins); 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;
}
}
} }

View File

@ -364,7 +364,6 @@ class AsciiTable
// //
foreach (explode("\r\n", $builder->renderTable()) as $value) { foreach (explode("\r\n", $builder->renderTable()) as $value) {
if ($value) { if ($value) {
echo $value.PHP_EOL;
$th_list[] = $value; $th_list[] = $value;
} }
} }