ソースを参照

refactor(command): 重构命令行服务初始化逻辑

- 修改 CommandService::init 方法签名,增加闭包参数
- 使用 Helper::extension_name_list() 替代 module_name_list()
- 优化命令行收集逻辑,使用闭包传递给 CoreService
- 移除 CoreService 中的冗余注释
runphp 7 ヶ月 前
コミット
129059a122
2 ファイル変更9 行追加10 行削除
  1. 7 8
      src/Service/CommandService.php
  2. 2 2
      src/Service/CoreService.php

+ 7 - 8
src/Service/CommandService.php

@@ -3,20 +3,19 @@ declare(strict_types=1);
 
 namespace SixShop\Core\Service;
 
+use SixShop\Core\Helper;
 use SixShop\Extension\system\ExtensionManager;
+use think\App;
 
 class CommandService
 {
-    public function init(App $app): void
+    public function init(App $app, \Closure $closure): void
     {
-        $app->re
-        $commands = $app->config->get('console.commands', []);
         $extensionManager = $app->make(ExtensionManager::class);
-        foreach (module_name_list() as $moduleName) {
-            $commands = array_merge($commands, $extensionManager->getExtension($moduleName)->getCommands());
+        $commands = [];
+        foreach (Helper::extension_name_list() as $extensionName) {
+            $commands += $extensionManager->getExtension($extensionName)->getCommands();
         }
-        $app->config->set([
-            'commands' => $commands
-        ], 'console');
+        $closure($commands);
     }
 }

+ 2 - 2
src/Service/CoreService.php

@@ -34,9 +34,9 @@ class CoreService extends Service
             $this->registerRoutes($this->app->make(RegisterRouteService::class)->init($this->app));
         });
 
-        /*$this->app->make(CommandService::class)->init(function ($commands){
+        $this->app->make(CommandService::class)->init($this->app, function ($commands) {
             $this->commands($commands);
-        });*/
+        });
     }
 
     public function initExtensionList(): void