| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- namespace App\Module\Admin\Providers;
- use App\Module\Admin\Events\AdminActionEvent;
- use App\Module\Admin\Listeners\AdminActionListener;
- use Illuminate\Support\Facades\Event;
- use Illuminate\Support\ServiceProvider;
- /**
- * Admin模块服务提供者
- *
- * 负责注册Admin模块的服务、事件监听器等
- */
- class AdminServiceProvider extends ServiceProvider
- {
- /**
- * 注册服务
- *
- * @return void
- */
- public function register()
- {
- // 注册配置文件
- $this->mergeConfigFrom(
- __DIR__ . '/../Config/admin.php',
- 'admin_module'
- );
- // 注册服务
- $this->registerServices();
- }
- /**
- * 启动服务
- *
- * @return void
- */
- public function boot()
- {
- // 注册事件监听器
- $this->registerEventListeners();
- // 注册命令
- $this->registerCommands();
- // 发布资源
- $this->publishResources();
- }
- /**
- * 注册服务
- *
- * @return void
- */
- protected function registerServices()
- {
- // 注册Admin服务
- $this->app->singleton('admin.service', function ($app) {
- return new \App\Module\Admin\Services\AdminService();
- });
- // 注册缓存服务
- $this->app->singleton('admin.cache', function ($app) {
- return new \App\Module\Admin\Services\CacheService();
- });
- // 注册日志服务
- $this->app->singleton('admin.log', function ($app) {
- return new \App\Module\Admin\Services\LogService();
- });
- }
- /**
- * 注册事件监听器
- *
- * @return void
- */
- protected function registerEventListeners()
- {
- Event::listen(
- AdminActionEvent::class,
- AdminActionListener::class
- );
- }
- /**
- * 注册命令
- *
- * @return void
- */
- protected function registerCommands()
- {
- if ($this->app->runningInConsole()) {
- // 暂时注释掉不存在的命令类
- // $this->commands([
- // \App\Module\Admin\Commands\AdminCacheCommand::class,
- // \App\Module\Admin\Commands\AdminMaintenanceCommand::class,
- // ]);
- }
- }
- /**
- * 发布资源
- *
- * @return void
- */
- protected function publishResources()
- {
- // 发布配置文件
- $this->publishes([
- __DIR__ . '/../Config/admin.php' => config_path('admin_module.php'),
- ], 'admin-config');
- // 发布视图文件
- $this->publishes([
- __DIR__ . '/../Resources/views' => resource_path('views/admin'),
- ], 'admin-views');
- // 发布静态资源
- $this->publishes([
- __DIR__ . '/../Resources/assets' => public_path('vendor/admin'),
- ], 'admin-assets');
- }
- /**
- * 获取提供的服务
- *
- * @return array
- */
- public function provides()
- {
- return [
- 'admin.service',
- 'admin.cache',
- 'admin.log',
- ];
- }
- }
|