| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace App\Module\SocialFarm\Providers;
- use Illuminate\Support\ServiceProvider;
- use Illuminate\Support\Facades\Event;
- /**
- * SocialFarm模块服务提供者
- */
- class SocialFarmServiceProvider extends ServiceProvider
- {
- /**
- * 注册服务
- */
- public function register(): void
- {
- // 注册配置文件
- $this->mergeConfigFrom(
- __DIR__ . '/../config/socialfarm.php',
- 'socialfarm'
- );
- }
- /**
- * 启动服务
- */
- public function boot(): void
- {
- // 发布配置文件
- if ($this->app->runningInConsole()) {
- $this->publishes([
- __DIR__ . '/../config/socialfarm.php' => config_path('socialfarm.php'),
- ], 'socialfarm-config');
- }
- // 注册事件监听器
- $this->registerEventListeners();
- // 注册命令
- $this->registerCommands();
- }
- /**
- * 注册事件监听器
- */
- protected function registerEventListeners(): void
- {
- // 偷菜成功事件
- Event::listen(
- \App\Module\SocialFarm\Events\CropStolenEvent::class,
- \App\Module\SocialFarm\Listeners\SendStealNotificationListener::class
- );
- Event::listen(
- \App\Module\SocialFarm\Events\CropStolenEvent::class,
- \App\Module\SocialFarm\Listeners\UpdateSocialStatsListener::class
- );
- // 农场访问事件
- Event::listen(
- \App\Module\SocialFarm\Events\FarmVisitedEvent::class,
- \App\Module\SocialFarm\Listeners\UpdateSocialStatsListener::class
- );
- // 互助行为事件
- Event::listen(
- \App\Module\SocialFarm\Events\HelpActionEvent::class,
- \App\Module\SocialFarm\Listeners\UpdateSocialStatsListener::class
- );
- }
- /**
- * 注册命令
- */
- protected function registerCommands(): void
- {
- if ($this->app->runningInConsole()) {
- $this->commands([
- \App\Module\SocialFarm\Commands\CleanExpiredLogsCommand::class,
- \App\Module\SocialFarm\Commands\SocialFarmStatsCommand::class,
- ]);
- }
- }
- /**
- * 获取提供的服务
- */
- public function provides(): array
- {
- return [];
- }
- }
|