TransferServiceProvider.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace App\Module\Transfer;
  3. use App\Module\Transfer\Commands\TransferProcessCommand;
  4. use App\Module\Transfer\Commands\TransferStatsCommand;
  5. use App\Module\Transfer\Commands\TransferCallbackCommand;
  6. use App\Module\Transfer\Commands\TransferCleanCommand;
  7. use App\Module\Transfer\Commands\InsertTransferAdminMenuCommand;
  8. use Illuminate\Support\ServiceProvider;
  9. /**
  10. * Transfer模块服务提供者
  11. */
  12. class TransferServiceProvider extends ServiceProvider
  13. {
  14. /**
  15. * 注册服务
  16. */
  17. public function register(): void
  18. {
  19. // 注册配置文件
  20. $this->mergeConfigFrom(
  21. __DIR__ . '/Config/transfer.php',
  22. 'transfer'
  23. );
  24. // 注册服务绑定
  25. $this->registerServices();
  26. }
  27. /**
  28. * 启动服务
  29. */
  30. public function boot(): void
  31. {
  32. // 发布配置文件
  33. $this->publishes([
  34. __DIR__ . '/Config/transfer.php' => config_path('transfer.php'),
  35. ], 'transfer-config');
  36. // 注册命令
  37. $this->registerCommands();
  38. // 注册事件监听器
  39. $this->registerEventListeners();
  40. // 注册中间件
  41. $this->registerMiddleware();
  42. }
  43. /**
  44. * 注册服务绑定
  45. */
  46. protected function registerServices(): void
  47. {
  48. // 注册Transfer服务
  49. $this->app->singleton('transfer', function () {
  50. return new \App\Module\Transfer\Services\TransferService();
  51. });
  52. // 注册外部API服务
  53. $this->app->singleton('transfer.api', function () {
  54. return new \App\Module\Transfer\Services\ExternalApiService();
  55. });
  56. }
  57. /**
  58. * 注册命令
  59. */
  60. protected function registerCommands(): void
  61. {
  62. if ($this->app->runningInConsole()) {
  63. $this->commands([
  64. TransferProcessCommand::class,
  65. TransferStatsCommand::class,
  66. TransferCallbackCommand::class,
  67. TransferCleanCommand::class,
  68. InsertTransferAdminMenuCommand::class,
  69. ]);
  70. }
  71. }
  72. /**
  73. * 注册事件监听器
  74. */
  75. protected function registerEventListeners(): void
  76. {
  77. // Transfer模块使用事件驱动架构
  78. // 事件监听器将在需要时自动注册
  79. }
  80. /**
  81. * 注册中间件
  82. */
  83. protected function registerMiddleware(): void
  84. {
  85. // Transfer模块不直接提供外部API
  86. // 通过OpenAPI模块进行对外开放和集成
  87. }
  88. /**
  89. * 获取提供的服务
  90. */
  91. public function provides(): array
  92. {
  93. return [
  94. 'transfer',
  95. 'transfer.api',
  96. ];
  97. }
  98. }