| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Module\Mex\Providers;
- use Illuminate\Support\ServiceProvider;
- use Illuminate\Console\Scheduling\Schedule;
- use Illuminate\Support\Facades\Event;
- /**
- * Mex模块服务提供者
- *
- * 负责注册Mex模块的服务、命令、计划任务等
- */
- class MexServiceProvider extends ServiceProvider
- {
- /**
- * 注册服务
- */
- public function register(): void
- {
- // 注册配置文件
- $this->mergeConfigFrom(
- __DIR__ . '/../Config/mex.php',
- 'mex'
- );
- // 注册单例服务 ;不注册服务
- // $this->registerServices();
- }
- /**
- * 启动服务
- */
- public function boot(): void
- {
- // 注册命令
- $this->registerCommands();
- // 注册计划任务;不注册计划任务,计划任务由项目组织
- // $this->registerSchedule();
- // 注册事件监听器
- $this->registerEventListeners();
- // 发布配置文件
- $this->publishes([
- __DIR__ . '/../Config/mex.php' => config_path('mex.php'),
- ], 'mex-config');
- }
- /**
- * 注册命令
- */
- protected function registerCommands(): void
- {
- if ($this->app->runningInConsole()) {
- $this->commands([
- \App\Module\Mex\Commands\MexUserBuyItemMatchCommand::class,
- \App\Module\Mex\Commands\MexUserSellItemMatchCommand::class,
- \App\Module\Mex\Commands\MexTestCommand::class,
- \App\Module\Mex\Commands\TestMultiCurrencyCommand::class,
- ]);
- }
- }
- /**
- * 注册事件监听器
- */
- protected function registerEventListeners(): void
- {
- Event::listen(
- \App\Module\Mex\Events\OrderCreatedEvent::class,
- \App\Module\Mex\Listeners\OrderCreatedListener::class
- );
- Event::listen(
- \App\Module\Mex\Events\OrderCompletedEvent::class,
- [\App\Module\Mex\Listeners\OrderCreatedListener::class, 'handleCompleted']
- );
- Event::listen(
- \App\Module\Mex\Events\TransactionCreatedEvent::class,
- \App\Module\Mex\Listeners\TransactionCreatedListener::class
- );
- }
- }
|