From 89f2675ed927bc59a872cb4aa12ac31722b76f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=81=E7=81=AB=E8=A1=8C=E8=80=85?= Date: Wed, 22 Sep 2021 20:38:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8F=92=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=8F=B0=E5=91=BD=E4=BB=A4=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Base/DzqCommand.php | 8 ++++---- src/Common/Utils.php | 12 ++++++------ src/Console/Kernel.php | 41 +++++++++++++++++++++++++++-------------- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/Base/DzqCommand.php b/src/Base/DzqCommand.php index 39af3db..a445019 100644 --- a/src/Base/DzqCommand.php +++ b/src/Base/DzqCommand.php @@ -17,9 +17,9 @@ namespace Discuz\Base; -use Illuminate\Console\Command; +use Discuz\Console\AbstractCommand; -abstract class DzqCommand extends Command +abstract class DzqCommand extends AbstractCommand { /** * 命名名称 @@ -53,7 +53,7 @@ abstract class DzqCommand extends Command echo PHP_EOL; echo sprintf('%s RUNNING ...', static::class) . PHP_EOL; echo PHP_EOL; - echo '/**************************START ' . date('Y-m-d H:i:s') . ' START****************************/' . PHP_EOL; + echo '************************** START ' . date('Y-m-d H:i:s') . ' START ****************************' . PHP_EOL; echo PHP_EOL; } @@ -61,7 +61,7 @@ abstract class DzqCommand extends Command { echo PHP_EOL; echo PHP_EOL; - echo '/**************************END ' . date('Y-m-d H:i:s') . ' END****************************/' . PHP_EOL; + echo '************************** END ' . date('Y-m-d H:i:s') . ' END ****************************' . PHP_EOL; echo PHP_EOL; } } diff --git a/src/Common/Utils.php b/src/Common/Utils.php index 9564a3f..f7c1921 100644 --- a/src/Common/Utils.php +++ b/src/Common/Utils.php @@ -206,15 +206,15 @@ class Utils if ($configName == '') { continue; } - $appBase = $pluginDir . '/' . $dirName . '/'; - $configPath = $appBase . $configName; - $viewPath = $viewName == '' ? null : $appBase . $viewName . '/'; - $databasePath = $databaseName == '' ? null : $appBase . $databaseName . '/'; - $consolePath = $consoleName == '' ? null : $appBase . $consoleName . '/'; + $basePath = $pluginDir . '/' . $dirName . '/'; + $configPath = $basePath . $configName; + $viewPath = $viewName == '' ? null : $basePath . $viewName . '/'; + $databasePath = $databaseName == '' ? null : $basePath . $databaseName . '/'; + $consolePath = $consoleName == '' ? null : $basePath . $consoleName . '/'; $config = require($configPath); if ($config['status'] == DzqConst::BOOL_YES) { $config['plugin_' . $config['app_id']] = [ - 'directory' => $appBase, + 'base' => $basePath, 'view' => $viewPath, 'database' => $databasePath, 'console' => $consolePath, diff --git a/src/Console/Kernel.php b/src/Console/Kernel.php index a902704..5dc9904 100644 --- a/src/Console/Kernel.php +++ b/src/Console/Kernel.php @@ -18,6 +18,7 @@ namespace Discuz\Console; +use Discuz\Common\Utils; use Discuz\Console\Event\Configuring; use Discuz\Foundation\SiteApp; use Illuminate\Console\Scheduling\Schedule; @@ -25,6 +26,7 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; use Discuz\Foundation\Application; use Illuminate\Contracts\Console\Kernel as KernelContract; +use Plugin\Activity\Console\Test1Command; use ReflectionClass; use Symfony\Component\Console\Application as ConsoleApplication; use Symfony\Component\Console\Command\Command; @@ -194,20 +196,31 @@ EOF; if (empty($paths)) { return; } - $namespace = $this->app->getNamespace(); - foreach ((new Finder)->in($paths)->files() as $command) { - $command = $namespace.str_replace( - ['/', '.php'], - ['\\', ''], - Str::after($command->getPathname(), realpath(app_path()).DIRECTORY_SEPARATOR) - ); - if (is_subclass_of($command, Command::class) && - ! (new ReflectionClass($command))->isAbstract()) { - $console->add($this->app->make($command)); + $commands = Finder::create()->in($paths)->files(); + foreach ($commands as $command) { + $command = '\App' . str_replace(['/', '.php'], ['\\', ''], Str::after($command->getPathname(), realpath(app_path()) . DIRECTORY_SEPARATOR)); + $this->doCommand($console, $command); + } + $pluginList = Utils::getPluginList(); + foreach ($pluginList as $item) { + $consolePath = $item['plugin_' . $item['app_id']]['console']; + if (empty($consolePath)) continue; + $commands = Finder::create()->in($consolePath)->files(); + foreach ($commands as $command) { + $command = '\Plugin' . str_replace(['/', '.php'], ['\\', ''], Str::after($command->getPathname(), base_path('plugin'))); + $this->doCommand($console, $command); } } } + private function doCommand(&$console, $command) + { + if (is_subclass_of($command, Command::class) && + !(new ReflectionClass($command))->isAbstract()) { + $console->add($this->app->make($command)); + } + } + /** * Get the timezone that should be used by default for scheduled events. * @@ -225,14 +238,14 @@ EOF; */ protected function scheduleCache() { - return ; + return; } /** * Parse the incoming Artisan command and its input. * - * @param string $command - * @param array $parameters + * @param string $command + * @param array $parameters * @return array */ protected function parseCommand($command, $parameters) @@ -243,7 +256,7 @@ EOF; $command = $this->app->make($command)->getName(); } - if (! isset($callingClass) && empty($parameters)) { + if (!isset($callingClass) && empty($parameters)) { $input = new StringInput($command); } else { array_unshift($parameters, $command); -- Gitee