Преглед изворни кода

refactor: 统一代码风格

runphp пре 2 недеља
родитељ
комит
dea577c71b
37 измењених фајлова са 113 додато и 65 уклоњено
  1. 2 2
      command.php
  2. 2 1
      config.php
  3. 1 0
      database/migrations/20250624125157_extension_config.php
  4. 1 0
      database/migrations/20250627061219_extension.php
  5. 1 0
      database/migrations/20250702110812_extension_add_category.php
  6. 1 0
      info.php
  7. 2 1
      route/admin.php
  8. 1 0
      src/Command/CoreExtensionConfigCommand.php
  9. 2 1
      src/Command/CrontabCommand.php
  10. 4 2
      src/Command/ExtensionManagementCommand.php
  11. 21 7
      src/Command/ExtensionScaffoldMakeCommand.php
  12. 2 1
      src/Config.php
  13. 4 2
      src/Controller/ExtensionConfigController.php
  14. 3 1
      src/Controller/ExtensionController.php
  15. 2 1
      src/Cron/SystemCron.php
  16. 2 2
      src/Entity/ExtensionEntity.php
  17. 2 1
      src/Event/CrontabWorkerStartEvent.php
  18. 3 2
      src/Event/GetCronJobsEvent.php
  19. 3 5
      src/Extension.php
  20. 6 3
      src/ExtensionManager.php
  21. 2 2
      src/ExtensionMysqlAdapter.php
  22. 2 2
      src/Hook/DebugHook.php
  23. 3 1
      src/Hook/ExtensionStatusHook.php
  24. 4 2
      src/Hook/GatheringCrontabEventHook.php
  25. 2 2
      src/Job/ClosureJob.php
  26. 9 7
      src/Log/Driver/FeiShu.php
  27. 2 2
      src/Middleware/AppendSqlDebugMiddleware.php
  28. 2 1
      src/Middleware/MacroPageMiddleware.php
  29. 3 1
      src/Migrate.php
  30. 3 2
      src/Model/ExtensionConfigModel.php
  31. 3 3
      src/Model/ExtensionModel.php
  32. 2 1
      src/Model/MigrationsModel.php
  33. 2 1
      src/Trait/ConfigTrait.php
  34. 2 2
      src/Trait/EventTrait.php
  35. 2 2
      src/helper.php
  36. 2 1
      tests/ExtensionManagerTest.php
  37. 3 1
      tests/Hook/GatheringCrontabEventHookTest.php

+ 2 - 2
command.php

@@ -1,15 +1,15 @@
 <?php
+
 declare(strict_types=1);
 
 use SixShop\System\Command\CoreExtensionConfigCommand;
 use SixShop\System\Command\CrontabCommand;
 use SixShop\System\Command\ExtensionManagementCommand;
 use SixShop\System\Command\ExtensionScaffoldMakeCommand;
-use SixShop\System\Command\ModelPropertyCommand;
 
 return [
     'core:config' => CoreExtensionConfigCommand::class,
     'extension:manage' => ExtensionManagementCommand::class,
     'extension:make' => ExtensionScaffoldMakeCommand::class,
     'crontab' => CrontabCommand::class,
-];
+];

+ 2 - 1
config.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 return [
@@ -85,4 +86,4 @@ return [
             ]
         ]
     ]
-];
+];

+ 1 - 0
database/migrations/20250624125157_extension_config.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 use Phinx\Migration\AbstractMigration;

+ 1 - 0
database/migrations/20250627061219_extension.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 use Phinx\Migration\AbstractMigration;

+ 1 - 0
database/migrations/20250702110812_extension_add_category.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 use Phinx\Migration\AbstractMigration;

+ 1 - 0
info.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 return [

+ 2 - 1
route/admin.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 use SixShop\System\Controller\{ExtensionConfigController, ExtensionController};
@@ -42,4 +43,4 @@ Route::resource('extension_config', ExtensionConfigController::class)->only([
     'description' => '扩展配置'
 ])->middleware([
     'auth'
-]);
+]);

+ 1 - 0
src/Command/CoreExtensionConfigCommand.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Command;

+ 2 - 1
src/Command/CrontabCommand.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Command;
@@ -63,4 +64,4 @@ class CrontabCommand extends Command
         });
         Worker::runAll();
     }
-}
+}

+ 4 - 2
src/Command/ExtensionManagementCommand.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Command;
@@ -9,12 +10,13 @@ use think\console\Input;
 use think\console\input\Argument;
 use think\console\Output;
 use think\console\Table;
+
 use function SixShop\Core\extension_path;
 
 class ExtensionManagementCommand extends Command
 {
-    const int FAILURE = 1;
-    const int SUCCESS = 0;
+    public const int FAILURE = 1;
+    public const int SUCCESS = 0;
 
     protected function configure(): void
     {

+ 21 - 7
src/Command/ExtensionScaffoldMakeCommand.php

@@ -1,15 +1,17 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Command;
 
-use function SixShop\Core\extension_path;
 use think\console\Command;
 use think\console\Input;
 use think\console\input\Argument;
 use think\console\input\Option;
 use think\console\Output;
 
+use function SixShop\Core\extension_path;
+
 class ExtensionScaffoldMakeCommand extends Command
 {
     protected function configure(): void
@@ -99,8 +101,12 @@ class ExtensionScaffoldMakeCommand extends Command
             $planFiles[] = "$base/src/Controller/Admin/ItemController.php";
             $planFiles[] = "$base/src/Controller/Admin/UploadController.php";
         }
-        if ($withService) $planFiles[] = "$base/src/Service/{$studly}Service.php";
-        if ($withEntity) $planFiles[] = "$base/src/Entity/{$studly}.php";
+        if ($withService) {
+            $planFiles[] = "$base/src/Service/{$studly}Service.php";
+        }
+        if ($withEntity) {
+            $planFiles[] = "$base/src/Entity/{$studly}.php";
+        }
         if ($withMigration) {
             $planFiles[] = "$base/config/install.sql";
             $planFiles[] = "$base/config/uninstall.sql";
@@ -118,7 +124,9 @@ class ExtensionScaffoldMakeCommand extends Command
             return 0;
         }
 
-        foreach ($dirs as $d) @mkdir($d, 0777, true);
+        foreach ($dirs as $d) {
+            @mkdir($d, 0777, true);
+        }
 
         // info.php
         // 生成完整 info.php(参考 guimi)
@@ -256,8 +264,12 @@ Route::get('dashboard/stats', [DashboardController::class, 'stats'])->middleware
 // 通用上传
 Route::post('upload', [UploadController::class, 'handle'])->middleware(['auth']);
 PHP, $module, $module, $module);
-        if ($withApi) file_put_contents("$base/route/api.php", $apiRoute);
-        if ($withAdmin) file_put_contents("$base/route/admin.php", $adminRoute);
+        if ($withApi) {
+            file_put_contents("$base/route/api.php", $apiRoute);
+        }
+        if ($withAdmin) {
+            file_put_contents("$base/route/admin.php", $adminRoute);
+        }
 
         // 控制器样板
         if ($withApi) {
@@ -529,7 +541,9 @@ TS, $module, $module);
 
         // 提示
         $output->writeln("<info>扩展骨架已生成:</info> $base");
-        if ($withFrontend) $output->writeln("<comment>前端模板:</comment> frontend/admin/src/views/{$module}");
+        if ($withFrontend) {
+            $output->writeln("<comment>前端模板:</comment> frontend/admin/src/views/{$module}");
+        }
         $output->writeln("<comment>下一步:</comment> 1) 根据业务完善 Service/Entity 2) 配置路由与菜单 3) 如需 FFI 执行 {$module}/build.sh");
         return 0;
     }

+ 2 - 1
src/Config.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System;
@@ -8,4 +9,4 @@ use SixShop\System\Trait\ConfigTrait;
 class Config
 {
     use ConfigTrait;
-}
+}

+ 4 - 2
src/Controller/ExtensionConfigController.php

@@ -1,13 +1,15 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Controller;
 
-use function SixShop\Core\success_response;
 use SixShop\System\ExtensionManager;
 use think\Request;
 use think\Response;
 
+use function SixShop\Core\success_response;
+
 class ExtensionConfigController
 {
     public function read(string $id, ExtensionManager $extensionManager): Response
@@ -24,4 +26,4 @@ class ExtensionConfigController
     {
         return success_response($extensionManager->saveConfig($id, $request->post()));
     }
-}
+}

+ 3 - 1
src/Controller/ExtensionController.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Controller;
@@ -10,6 +11,7 @@ use think\App;
 use think\facade\Event;
 use think\paginator\driver\Bootstrap;
 use think\Response;
+
 use function SixShop\Core\extension_path;
 use function SixShop\Core\page_response;
 use function SixShop\Core\success_response;
@@ -133,4 +135,4 @@ class ExtensionController
                 ->header(['Content-Type' => 'text/plain;charset=utf-8']);
         }
     }
-}
+}

+ 2 - 1
src/Cron/SystemCron.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Cron;
@@ -34,4 +35,4 @@ class SystemCron
         $this->cache->set('crontab_list', $crontabList);
         $this->isStart = true;
     }
-}
+}

+ 2 - 2
src/Entity/ExtensionEntity.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Entity;
@@ -11,5 +12,4 @@ use SixShop\System\Model\ExtensionModel;
  */
 class ExtensionEntity extends BaseEntity
 {
-
-}
+}

+ 2 - 1
src/Event/CrontabWorkerStartEvent.php

@@ -1,8 +1,9 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Event;
 
 class CrontabWorkerStartEvent
 {
-}
+}

+ 3 - 2
src/Event/GetCronJobsEvent.php

@@ -1,10 +1,11 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\System\Event;
 
 use think\Collection;
 
 class GetCronJobsEvent extends Collection
 {
-
-}
+}

+ 3 - 5
src/Extension.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System;
@@ -10,15 +11,12 @@ use SixShop\System\Enum\ExtensionStatusEnum;
 use SixShop\System\Hook\DebugHook;
 use SixShop\System\Hook\ExtensionStatusHook;
 use SixShop\System\Hook\GatheringCrontabEventHook;
-use SixShop\System\Service\FrontendDeployService;
 use think\db\exception\PDOException;
-use think\facade\Event;
 
 use function SixShop\Core\extension_name_list;
 
 class Extension extends ExtensionAbstract
 {
-
     public function __construct(private readonly AutoloadService $autoloadService)
     {
     }
@@ -75,7 +73,7 @@ class Extension extends ExtensionAbstract
         parent::boot();
     }
 
-    public  function available(): true
+    public function available(): true
     {
         return true;
     }
@@ -84,4 +82,4 @@ class Extension extends ExtensionAbstract
     {
         return dirname(__DIR__);
     }
-}
+}

+ 6 - 3
src/ExtensionManager.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System;
@@ -20,6 +21,7 @@ use think\facade\Event;
 use think\facade\Log;
 use think\facade\Validate;
 use think\Service;
+
 use function SixShop\Core\extension_name_list;
 
 class ExtensionManager extends Service
@@ -79,7 +81,7 @@ class ExtensionManager extends Service
             return $key ? null : [];
         }
         if ($onlyValue) {
-            $extensionConfig = array_map(fn($item) => $item['value'], $extensionConfig);
+            $extensionConfig = array_map(fn ($item) => $item['value'], $extensionConfig);
         }
 
         return $key != '' ? $extensionConfig[$key] : $extensionConfig;
@@ -201,7 +203,8 @@ class ExtensionManager extends Service
             sprintf(ExtensionModel::EXTENSION_INFO_CACHE_KEY, $name),
             function () use ($name) {
                 return $this->initExtensionInfo($name);
-            }));
+            }
+        ));
     }
 
     private function initExtensionInfo(string $name): ExtensionModel
@@ -329,4 +332,4 @@ class ExtensionManager extends Service
         Event::trigger('after_read_extension_config_' . $extensionID, $configCollection);
         return $configCollection;
     }
-}
+}

+ 2 - 2
src/ExtensionMysqlAdapter.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System;
@@ -12,5 +13,4 @@ use Phinx\Db\Adapter\MysqlAdapter;
  */
 class ExtensionMysqlAdapter extends MysqlAdapter
 {
-
-}
+}

+ 2 - 2
src/Hook/DebugHook.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Hook;
@@ -10,7 +11,6 @@ use think\event\HttpRun;
 
 class DebugHook
 {
-
     public function __construct(private App $app)
     {
 
@@ -20,4 +20,4 @@ class DebugHook
     {
         $this->app->middleware->add(AppendSqlDebugMiddleware::class);
     }
-}
+}

+ 3 - 1
src/Hook/ExtensionStatusHook.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Hook;
@@ -9,6 +10,7 @@ use SixShop\Core\Event\BeforeRegisterRouteEvent;
 use SixShop\Core\Request;
 use SixShop\System\Enum\ExtensionStatusEnum;
 use SixShop\System\ExtensionManager;
+
 use function SixShop\Core\error_response;
 
 class ExtensionStatusHook
@@ -31,4 +33,4 @@ class ExtensionStatusHook
             default => error_response(msg: '模块`' . $moduleName . '`未启用', httpCode: 403)
         };
     }
-}
+}

+ 4 - 2
src/Hook/GatheringCrontabEventHook.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Hook;
@@ -13,6 +14,7 @@ use SixShop\System\ExtensionManager;
 use think\App;
 use think\facade\Log;
 use Workerman\Crontab\Crontab;
+
 use function SixShop\Core\extension_name_list;
 
 class GatheringCrontabEventHook
@@ -46,7 +48,7 @@ class GatheringCrontabEventHook
             foreach ($objectAttts as $attribute) {
                 $cronInstance = $attribute->newInstance();
                 if (is_callable($cronJob)) {
-                    new Crontab($cronInstance->rule, $cronJob, $cronInstance->name?:$cronJobClass);
+                    new Crontab($cronInstance->rule, $cronJob, $cronInstance->name ?: $cronJobClass);
                 } else {
                     Log::warning("Cron job {$cronJobClass} is not callable");
                 }
@@ -61,4 +63,4 @@ class GatheringCrontabEventHook
             }
         }
     }
-}
+}

+ 2 - 2
src/Job/ClosureJob.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Job;
@@ -8,11 +9,10 @@ use SixShop\Core\Job\BaseJob;
 
 class ClosureJob extends BaseJob
 {
-
     protected bool $isClosure = true;
 
     protected function execute(Closure $data)
     {
         return value($data);
     }
-}
+}

+ 9 - 7
src/Log/Driver/FeiShu.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\System\Log\Driver;
 
 use think\contract\LogHandlerInterface;
@@ -7,11 +9,11 @@ use think\contract\LogHandlerInterface;
 class FeiShu implements LogHandlerInterface
 {
     private $curlHandle = null;
-    
+
     public function __construct(private array $config = [])
     {
     }
-    
+
     public function __destruct()
     {
         if ($this->curlHandle) {
@@ -71,7 +73,7 @@ class FeiShu implements LogHandlerInterface
                 CURLOPT_SSL_VERIFYHOST => false
             ]);
         }
-        
+
         // 每次请求设置特定的 URL 和数据
         curl_setopt_array($this->curlHandle, [
             CURLOPT_URL => $url,
@@ -86,11 +88,11 @@ class FeiShu implements LogHandlerInterface
         if ($error || $httpCode !== 200) {
             // 发送失败,可以选择记录到文件或其他方式
             error_log(sprintf(
-                'FeiShu webhook send failed: %s, HTTP Code: %d, Response: %s', 
-                $error ?: 'Unknown error', 
-                $httpCode, 
+                'FeiShu webhook send failed: %s, HTTP Code: %d, Response: %s',
+                $error ?: 'Unknown error',
+                $httpCode,
                 $response
             ));
         }
     }
-}
+}

+ 2 - 2
src/Middleware/AppendSqlDebugMiddleware.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Middleware;
@@ -8,7 +9,6 @@ use think\DbManager;
 use think\Request;
 use think\Response;
 
-
 class AppendSqlDebugMiddleware
 {
     private array $logList = [];
@@ -32,4 +32,4 @@ class AppendSqlDebugMiddleware
 
         return $response;
     }
-}
+}

+ 2 - 1
src/Middleware/MacroPageMiddleware.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Middleware;
@@ -24,4 +25,4 @@ class MacroPageMiddleware
         });
         return $next($request);
     }
-}
+}

+ 3 - 1
src/Migrate.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System;
@@ -12,6 +13,7 @@ use Phinx\Util\Util;
 use SixShop\System\Model\MigrationsModel;
 use think\App;
 use think\Model;
+
 use function SixShop\Core\extension_path;
 
 class Migrate
@@ -287,4 +289,4 @@ class Migrate
         }
         return array_values($migrations);
     }
-}
+}

+ 3 - 2
src/Model/ExtensionConfigModel.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Model;
@@ -41,7 +42,7 @@ class ExtensionConfigModel extends Model
         return match ($data['type']) {
             'radio', 'select', 'elTreeSelect', 'input' => (string)$firstOrSelf($raw),
             'switch' => (bool)$raw,
-            'timePicker', 'colorPicker', 'datePicker', 'fcEditor' => (fn($val) => (is_array($val) && count($val) == 1) ? (array_values($val)[0] ?? '') : $val)($raw),
+            'timePicker', 'colorPicker', 'datePicker', 'fcEditor' => (fn ($val) => (is_array($val) && count($val) == 1) ? (array_values($val)[0] ?? '') : $val)($raw),
             default => $raw,
         };
     }
@@ -55,4 +56,4 @@ class ExtensionConfigModel extends Model
             'jsonAssoc' => true,
         ];
     }
-}
+}

+ 3 - 3
src/Model/ExtensionModel.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Model;
@@ -33,6 +34,7 @@ use think\model\concern\SoftDelete;
  */
 class ExtensionModel extends Model
 {
+    use SoftDelete;
     public const string EXTENSION_INFO_CACHE_KEY = 'extension_info:%s';
 
     public function getStatusTextAttr($value, $data): string
@@ -40,8 +42,6 @@ class ExtensionModel extends Model
         return $data['status']->toString();
     }
 
-    use SoftDelete;
-
     public function onAfterWrite($model): void
     {
         Cache::delete(sprintf(self::EXTENSION_INFO_CACHE_KEY, $model->id));
@@ -57,4 +57,4 @@ class ExtensionModel extends Model
             ]
         ];
     }
-}
+}

+ 2 - 1
src/Model/MigrationsModel.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Model;
@@ -14,4 +15,4 @@ class MigrationsModel extends Model
             'pk' => 'version',
         ];
     }
-}
+}

+ 2 - 1
src/Trait/ConfigTrait.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Trait;
@@ -46,4 +47,4 @@ trait ConfigTrait
         $name = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $name));
         return $this->getConfig($name);
     }
-}
+}

+ 2 - 2
src/Trait/EventTrait.php

@@ -1,9 +1,9 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System\Trait;
 
-
 use think\facade\Event;
 
 trait EventTrait
@@ -14,4 +14,4 @@ trait EventTrait
         Event::trigger($event);
         return $event;
     }
-}
+}

+ 2 - 2
src/helper.php

@@ -1,9 +1,9 @@
 <?php
+
 declare(strict_types=1);
 
 use SixShop\System\ExtensionManager;
 
-
 if (!function_exists('extension_config')) {
     /**
      * 获取模块配置
@@ -26,4 +26,4 @@ if (!function_exists('array_to_map')) {
         }
         return $map;
     }
-}
+}

+ 2 - 1
tests/ExtensionManagerTest.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace SixShop\System;
@@ -21,4 +22,4 @@ class ExtensionManagerTest extends TestCase
     {
         $result = array_to_map(app(ExtensionManager::class)->getExtensionConfig('system', 'category'), 'code', 'text');
     }
-}
+}

+ 3 - 1
tests/Hook/GatheringCrontabEventHookTest.php

@@ -1,5 +1,7 @@
 <?php
+
 declare(strict_types=1);
+
 namespace SixShop\System\Hook;
 
 use PHPUnit\Framework\Attributes\Test;
@@ -17,4 +19,4 @@ class GatheringCrontabEventHookTest extends TestCase
     {
         $this->gatheringCrontabEventHook->onWorkerStart();
     }
-}
+}