AdminServiceProvider.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 registerEventListeners()
  44. {
  45. Event::listen(
  46. AdminActionEvent::class,
  47. AdminActionListener::class
  48. );
  49. }
  50. /**
  51. * 注册命令
  52. *
  53. * @return void
  54. */
  55. protected function registerCommands()
  56. {
  57. if ($this->app->runningInConsole()) {
  58. // 暂时注释掉不存在的命令类
  59. // $this->commands([
  60. // \App\Module\Admin\Commands\AdminCacheCommand::class,
  61. // \App\Module\Admin\Commands\AdminMaintenanceCommand::class,
  62. // ]);
  63. }
  64. }
  65. /**
  66. * 发布资源
  67. *
  68. * @return void
  69. */
  70. protected function publishResources()
  71. {
  72. // 发布配置文件
  73. $this->publishes([
  74. __DIR__ . '/../Config/admin.php' => config_path('admin_module.php'),
  75. ], 'admin-config');
  76. // 发布视图文件
  77. $this->publishes([
  78. __DIR__ . '/../Resources/views' => resource_path('views/admin'),
  79. ], 'admin-views');
  80. // 发布静态资源
  81. $this->publishes([
  82. __DIR__ . '/../Resources/assets' => public_path('vendor/admin'),
  83. ], 'admin-assets');
  84. }
  85. /**
  86. * 获取提供的服务
  87. *
  88. * @return array
  89. */
  90. public function provides()
  91. {
  92. return [
  93. 'admin.service',
  94. 'admin.cache',
  95. 'admin.log',
  96. ];
  97. }
  98. }