| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Module\Fund\Providers;
- use App\Module\AppGame\Events\LoginSuccessEvent;
- use App\Module\Fund\Events\FundChangedEvent;
- use App\Module\Fund\Events\FundStatusChangedEvent;
- use App\Module\Fund\Events\FundTransferEvent;
- use App\Module\Fund\Listeners\FundEventListener;
- use App\Module\Fund\Listeners\LoginSuccessListener;
- use Illuminate\Support\ServiceProvider;
- /**
- * 资金模块服务提供者
- */
- class FundServiceProvider extends ServiceProvider
- {
- /**
- * 事件到监听器的映射
- *
- * @var array
- */
- protected $listen = [
- FundChangedEvent::class => [
- FundEventListener::class . '@handleFundChanged',
- ],
- FundTransferEvent::class => [
- FundEventListener::class . '@handleFundTransfer',
- ],
- FundStatusChangedEvent::class => [
- FundEventListener::class . '@handleFundStatusChanged',
- ],
- LoginSuccessEvent::class => [
- LoginSuccessListener::class . '@handle',
- ],
- ];
- /**
- * 需要注册的订阅者
- *
- * @var array
- */
- protected $subscribe = [
- FundEventListener::class,
- ];
- /**
- * 注册服务
- *
- * @return void
- */
- public function register(): void
- {
- // 注册服务...
- $this->app->singleton('fund.account.service', function ($app) {
- return new \App\Module\Fund\Services\AccountService();
- });
- $this->app->singleton('fund.log.service', function ($app) {
- return new \App\Module\Fund\Services\LogService();
- });
- }
- /**
- * 启动服务
- *
- * @return void
- */
- public function boot(): void
- {
- // 注册事件监听器
- $this->registerEvents();
- // 注册命令
- if ($this->app->runningInConsole()) {
- $this->commands([
- \App\Module\Fund\Commands\CheckUserLogsCommand::class,
- \App\Module\Fund\Commands\TestLoginAccountCreationCommand::class,
- ]);
- }
- }
- /**
- * 注册事件和监听器
- *
- * @return void
- */
- protected function registerEvents(): void
- {
- $events = $this->app['events'];
- foreach ($this->listen as $event => $listeners) {
- foreach ($listeners as $listener) {
- $events->listen($event, $listener);
- }
- }
- foreach ($this->subscribe as $subscriber) {
- $events->subscribe($subscriber);
- }
- }
- }
|