TransferServiceProvider.php 2.3 KB

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