AdminServiceProvider.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace App\Module\Admin\Providers;
  3. use App\Module\Admin\Events\AdminActionEvent;
  4. use App\Module\Admin\Listeners\AdminActionListener;
  5. use Illuminate\Support\Facades\Event;
  6. use Illuminate\Support\ServiceProvider;
  7. /**
  8. * Admin模块服务提供者
  9. *
  10. * 负责注册Admin模块的服务、事件监听器等
  11. */
  12. class AdminServiceProvider extends ServiceProvider
  13. {
  14. /**
  15. * 注册服务
  16. *
  17. * @return void
  18. */
  19. public function register()
  20. {
  21. // 注册服务,不需要注册服务
  22. // $this->registerServices();
  23. }
  24. /**
  25. * 启动服务
  26. *
  27. * @return void
  28. */
  29. public function boot()
  30. {
  31. // 注册事件监听器
  32. $this->registerEventListeners();
  33. // 注册命令
  34. $this->registerCommands();
  35. // 发布资源,没有可发布的资源
  36. // $this->publishResources();
  37. }
  38. /**
  39. * 注册服务
  40. *
  41. * @return void
  42. */
  43. protected function registerServices()
  44. {
  45. // 注册 AdminService
  46. $this->app->singleton('admin.service', function ($app) {
  47. return new \App\Module\Admin\Services\AdminService();
  48. });
  49. // 注册 CacheService
  50. $this->app->singleton('admin.cache', function ($app) {
  51. return new \App\Module\Admin\Services\CacheService();
  52. });
  53. // 注册 LogService
  54. $this->app->singleton('admin.log', function ($app) {
  55. return new \App\Module\Admin\Services\LogService();
  56. });
  57. }
  58. /**
  59. * 注册事件监听器
  60. *
  61. * @return void
  62. */
  63. protected function registerEventListeners()
  64. {
  65. Event::listen(
  66. AdminActionEvent::class,
  67. AdminActionListener::class
  68. );
  69. }
  70. /**
  71. * 注册命令
  72. *
  73. * @return void
  74. */
  75. protected function registerCommands()
  76. {
  77. if ($this->app->runningInConsole()) {
  78. // 暂时注释掉不存在的命令类
  79. // $this->commands([
  80. // \App\Module\Admin\Commands\AdminCacheCommand::class,
  81. // \App\Module\Admin\Commands\AdminMaintenanceCommand::class,
  82. // ]);
  83. }
  84. }
  85. }