소스 검색

refactor(system): 优化系统核心代码结构

- 移除冗余的 getInfo 方法调用
- 删除废弃的日志文件切换定时任务
- 统一中间件添加方法返回类型
- 更新扩展可用性检查返回值类型
- 规范数据库迁移版本获取方法签名
- 明确适配器获取方法返回类型声明
- 完善定时任务收集事件钩子注释
- 标准化扩展名称列表函数调用方式
runphp 3 달 전
부모
커밋
744225aa2b
6개의 변경된 파일11개의 추가작업 그리고 14개의 파일을 삭제
  1. 0 1
      src/Command/CoreExtensionConfigCommand.php
  2. 0 6
      src/Cron/SystemCron.php
  3. 1 1
      src/Extension.php
  4. 1 1
      src/Hook/ExtensionStatusHook.php
  5. 5 1
      src/Hook/GatheringCrontabEventHook.php
  6. 4 4
      src/Migrate.php

+ 0 - 1
src/Command/CoreExtensionConfigCommand.php

@@ -37,7 +37,6 @@ class CoreExtensionConfigCommand extends Command
         }
         foreach ($moduleList as $moduleName) {
             $extension = $extensionManager->getExtension($moduleName);
-            $info = $extension->getInfo();
             try {
                 $config = $extensionManager->getExtensionConfig($moduleName);
             } catch (PDOException $e) {

+ 0 - 6
src/Cron/SystemCron.php

@@ -34,10 +34,4 @@ class SystemCron
         $this->cache->set('crontab_list', $crontabList);
         $this->isStart = true;
     }
-
-    #[Cron('1 0 0 * * *', 'system.cron.change_log_file')]
-    public function changeLogFile(): void
-    {
-        Worker::$logFile = root_path('runtime/log')  . date('Ymd') . '_crontab.log';
-    }
 }

+ 1 - 1
src/Extension.php

@@ -98,7 +98,7 @@ class Extension extends ExtensionAbstract
         });
     }
 
-    public  function available()
+    public  function available(): true
     {
         return true;
     }

+ 1 - 1
src/Hook/ExtensionStatusHook.php

@@ -19,7 +19,7 @@ class ExtensionStatusHook
     }
 
     #[Hook(BeforeRegisterRouteEvent::class)]
-    public function addMiddleware(BeforeRegisterRouteEvent $event)
+    public function addMiddleware(BeforeRegisterRouteEvent $event): void
     {
         $event->addMiddleware($this->handle(...));
     }

+ 5 - 1
src/Hook/GatheringCrontabEventHook.php

@@ -13,6 +13,7 @@ use SixShop\System\Event\GetCronJobsEvent;
 use SixShop\System\ExtensionManager;
 use think\App;
 use Workerman\Crontab\Crontab;
+use function SixShop\Core\extension_name_list;
 
 class GatheringCrontabEventHook
 {
@@ -20,12 +21,15 @@ class GatheringCrontabEventHook
     {
     }
 
+    /**
+     * @throws \ReflectionException
+     */
     #[Hook(CrontabWorkerStartEvent::class)]
     public function onWorkerStart(): void
     {
         $extensionManager = $this->app->make(ExtensionManager::class);
         $event = new GetCronJobsEvent();
-        foreach (Helper::extension_name_list() as $extensionName) {
+        foreach (extension_name_list() as $extensionName) {
             $extension = $extensionManager->getExtension($extensionName);
             if ($extension->available()) {
                 $cronJobs = $extension->getCronJobs();

+ 4 - 4
src/Migrate.php

@@ -117,12 +117,12 @@ class Migrate
         return $installVersions;
     }
 
-    protected function getVersions()
+    protected function getVersions(): array
     {
         return $this->getAdapter()->getVersions();
     }
 
-    public function getAdapter()
+    public function getAdapter(): \Phinx\Db\Adapter\AdapterWrapper|AdapterInterface
     {
         if (isset($this->adapter)) {
             return $this->adapter;
@@ -196,7 +196,7 @@ class Migrate
         return $version;
     }
 
-    protected function executeMigration(MigrationInterface $migration, $direction = MigrationInterface::UP)
+    protected function executeMigration(MigrationInterface $migration, $direction = MigrationInterface::UP): void
     {
 
         $startTime = time();
@@ -268,7 +268,7 @@ class Migrate
         }
     }
 
-    protected function getVersionLog()
+    protected function getVersionLog(): array
     {
         return $this->getAdapter()->getVersionLog();
     }