From 8a9148726b98549e9d44331430ec96bb9d6c6270 Mon Sep 17 00:00:00 2001 From: Lkeme <19500576+lkeme@users.noreply.github.com> Date: Tue, 5 Apr 2022 14:41:33 +0800 Subject: [PATCH] [refactor(*)]: prepare --- LICENSE | 2 +- composer.json | 1 + index.php | 16 ++- src/core/App.php | 16 ++- src/core/BCommand.php | 16 ++- src/core/Cache.php | 2 +- src/core/Config.php | 16 ++- src/core/Curl.php | 16 ++- src/core/Device.php | 16 ++- src/core/Env.php | 16 ++- src/core/Helpers.php | 16 ++- src/core/HttpClient.php | 2 +- src/core/Log.php | 16 ++- src/core/Task.php | 16 ++- src/exception/SingletonException.php | 16 ++- src/exception/TaskException.php | 16 ++- src/plugin/ActivityLottery.php | 16 ++- src/plugin/AloneTcpClient.php | 16 ++- src/plugin/AnchorRaffle.php | 16 ++- src/plugin/AwardRecord.php | 16 ++- src/plugin/Barrage.php | 16 ++- src/plugin/BpConsumption.php | 16 ++- src/plugin/CapsuleLottery.php | 16 ++- src/plugin/CheckUpdate.php | 16 ++- src/plugin/Competition.php | 16 ++- src/plugin/DailyBag.php | 16 ++- src/plugin/DailyTask.php | 16 ++- src/plugin/DataTreating.php | 16 ++- src/plugin/DoubleHeart.php | 16 ++- src/plugin/Forward.php | 16 ++- src/plugin/GiftHeart.php | 16 ++- src/plugin/GiftRaffle.php | 16 ++- src/plugin/GiftSend.php | 16 ++- src/plugin/GroupSignIn.php | 16 ++- src/plugin/GuardRaffle.php | 16 ++- src/plugin/Judge.php | 16 ++- src/plugin/Live.php | 16 ++- src/plugin/LiveReservation.php | 16 ++- src/plugin/Login.php | 17 ++- src/plugin/MainSite.php | 16 ++- src/plugin/ManGa.php | 16 ++- src/plugin/MaterialObject.php | 16 ++- src/plugin/Notice.php | 16 ++- src/plugin/PkRaffle.php | 16 ++- src/plugin/PolishTheMedal.php | 16 ++- src/plugin/RedPocketRaffle.php | 16 ++- src/plugin/Schedule.php | 16 ++- src/plugin/Sign.php | 16 ++- src/plugin/Silver.php | 16 ++- src/plugin/Silver2Coin.php | 16 ++- src/plugin/SmallHeart.php | 16 ++- src/plugin/Statistics.php | 16 ++- src/plugin/StormRaffle.php | 16 ++- src/plugin/User.php | 16 ++- src/plugin/VipPrivilege.php | 16 ++- src/plugin/ZoneTcpClient.php | 16 ++- src/plugins/BasePlugin.php | 120 +++++++++++++++++++ src/plugins/Example/Example.php | 43 +++++++ src/plugins/Plugins.php | 169 +++++++++++++++++++++++++++ src/script/BaseTask.php | 17 ++- src/script/DelDynamic.php | 17 ++- src/script/UnFollow.php | 17 ++- src/script/User.php | 17 ++- src/tool/ArrayToTextTable.php | 2 +- src/tool/BvToAv.php | 2 +- src/tool/Common.php | 16 ++- src/tool/DumpMemory.php | 2 +- src/tool/Faker.php | 2 +- src/tool/File.php | 2 +- src/tool/Generator.php | 2 +- src/tool/Path.php | 2 +- src/tool/UserAgent.php | 2 +- src/util/AllotTasks.php | 16 ++- src/util/BaseRaffle.php | 16 ++- src/util/FilterWords.php | 16 ++- src/util/Singleton.php | 16 ++- src/util/TimeLock.php | 16 ++- src/util/XliveHeartBeat.php | 16 ++- tool/ConfigGenerator.php | 2 +- 79 files changed, 1295 insertions(+), 75 deletions(-) create mode 100644 src/plugins/BasePlugin.php create mode 100644 src/plugins/Example/Example.php create mode 100644 src/plugins/Plugins.php diff --git a/LICENSE b/LICENSE index dd68ab2..d0b5d78 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Lkeme +Copyright (c) 2022 Lkeme Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index 9bd6e37..cfeae6e 100644 --- a/composer.json +++ b/composer.json @@ -37,6 +37,7 @@ "psr-4": { "BiliHelper\\Core\\": "src/core", "BiliHelper\\Plugin\\": "src/plugin", + "BiliHelper\\Plugins\\": "src/plugins", "BiliHelper\\Util\\": "src/util", "BiliHelper\\Tool\\": "src/tool", "BiliHelper\\Script\\": "src/script", diff --git a/index.php b/index.php index 7094899..bd53619 100644 --- a/index.php +++ b/index.php @@ -1,11 +1,25 @@ _view; + } + + /** + * @use 视图 + * @param mixed $view + */ + public function setView(mixed $view): void + { + $this->_view = $view; + } + + /** + * @use 渲染视图 + * @param $view + * @param array $params + */ + public function render($view, array $params = []) + { + + } + + /** + * @use 渲染视图文件 + * @param $file + * @param array $params + */ + public function renderFile($file, array $params = []) + { + } + + /** + * @use 视图路径 + */ + public function getViewPath() + { + } + + /** + * @use 安装 + * @return bool + */ + public function install(): bool + { + return true; + } + + /** + * @use 卸载 + * @return bool + */ + public function uninstall(): bool + { + return true; + } + + /** + * @use 开启 + * @return bool + */ + public function open(): bool + { + return true; + } + + /** + * @use 关闭 + * @return bool + */ + public function close(): bool + { + return true; + } + + /** + * @use 更新 + * @return bool + */ + public function upgrade(): bool + { + return true; + } +} \ No newline at end of file diff --git a/src/plugins/Example/Example.php b/src/plugins/Example/Example.php new file mode 100644 index 0000000..20cb5a3 --- /dev/null +++ b/src/plugins/Example/Example.php @@ -0,0 +1,43 @@ +register('Example', $this, 'example'); + } + + + public function example($example): string + { + return "插件" . $example; + } + +} \ No newline at end of file diff --git a/src/plugins/Plugins.php b/src/plugins/Plugins.php new file mode 100644 index 0000000..9dfd498 --- /dev/null +++ b/src/plugins/Plugins.php @@ -0,0 +1,169 @@ +detector(); + } + + /** + * @use 防止使用clone克隆对象 + */ + private function __clone() + { + } + + /** + * @use Singleton + * @param mixed ...$args + * @return \BiliHelper\Plugins\Plugins + */ + public static function getInstance(...$args): Plugins + { + // 判断$instance是否是Singleton的对象,不是则创建 + if (!self::$instance instanceof self) { + self::$instance = new self(...$args); + } + return self::$instance; + } + + /** + * @use 初始化所有插件类 + * @access public + * @return void + */ + public function detector() + { + //主要功能为将插件需要执行功能放入 $_staff + $plugins = $this->get_active_plugins(); + + if ($plugins) { + foreach ($plugins as $plugin) { + // 这里将所有插件践行初始化 + // 路径请自己注意 + if (@file_exists($plugin['path'])) { + include_once($plugin['path']); + // 此时设定 文件夹名称 文件名称 类名 是统一的 如果想设定不统一请自己在get_active_plugins()内进行实现 + $class = $plugin['name']; + if (class_exists($class)) { + // 初始化所有插件类 + new $class($this); + } + } + } + } + } + + /** + * 这里是在插件中使用的方法 用来注册插件 + * + * @param string $hook + * @param object $class_name + * @param string $method + */ + public function register(string $hook, object &$class_name, string $method) + { + // 获取类名和方法名链接起来做下标 + $func_class = get_class($class_name) . '->' . $method; + // 将类和方法放入监听数组中 以$func_class做下标 + $this->_staff[$hook][$func_class] = array(&$class_name, $method); + + } + + /** + * 这个是全局使用的触发钩子动作方法 + * + * @param string $hook + * @param string $data + * @return string + */ + public function trigger(string $hook, string $data = ''): string + { + // 首先需要判断一下$hook 存不存在 + + if (isset($this->_staff[$hook]) && is_array($this->_staff[$hook]) && count($this->_staff[$hook]) > 0) { + $plugin_func_result = ''; + // 如果存在定义 $plugin_func_result + foreach ($this->_staff[$hook] as $staff) { + // 如果只是记录 请不要返回 + $plugin_func_result = ''; + $class = &$staff[0]; // 引用过来的类 + $method = $staff[1]; // 类下面的方法 + if (method_exists($class, $method)) { + $func_result = $class->$method($data); + if (is_numeric($func_result)) { + // 这里判断返回值是不是字符串,如果不是将不进行返回到页面上 + $plugin_func_result .= $func_result; + } + + } + } + } + + return $plugin_func_result ?? ''; + } + + /** + * 获取插件信息 + */ + public function get_active_plugins(): array + { + // 既假定了插件在根目录的/plugin + // 我们再次假定插件的入口和插件文件夹的名字是一样的 + // 既假定了插件在根目录的/plugin + // 注意:这个执行文件我放在了根目录 以下路径请根据实际情况获取 + + $plugin_dir_path = '.' . DIRECTORY_SEPARATOR . 'plugin' . DIRECTORY_SEPARATOR; + + $plugin_dir_name_arr = scandir($plugin_dir_path); + + $plugins = array(); + foreach ($plugin_dir_name_arr as $k => $v) { + if ($v == "." || $v == "..") { + continue; + } + if (is_dir($plugin_dir_path . $v)) { + $path = $plugin_dir_path . $v . DIRECTORY_SEPARATOR . $v . '.php'; + $plugins[] = ['name' => $v, 'path' => $path]; + } + + } + return $plugins; + } + + + + + +} \ No newline at end of file diff --git a/src/script/BaseTask.php b/src/script/BaseTask.php index 6b0ed1f..69bda25 100644 --- a/src/script/BaseTask.php +++ b/src/script/BaseTask.php @@ -1,10 +1,25 @@