| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace App\Module\OpenAPI\Providers;
- use App\Module\OpenAPI\Events\AppCreatedEvent;
- use App\Module\OpenAPI\Listeners\AppCreatedListener;
- use Illuminate\Support\Facades\Event;
- use Illuminate\Support\ServiceProvider;
- /**
- * OpenAPI模块服务提供者
- *
- * 专注于后台管理功能,使用注解路由,不注册API路由和资源
- */
- class OpenAPIServiceProvider extends ServiceProvider
- {
- /**
- * 注册服务
- *
- * @return void
- */
- public function register()
- {
- // 注册配置文件
- $this->mergeConfigFrom(
- __DIR__ . '/../Config/openapi.php',
- 'openapi'
- );
- // 注册服务
- $this->registerServices();
- }
- /**
- * 启动服务
- *
- * @return void
- */
- public function boot()
- {
- // 注册事件监听器
- $this->registerEventListeners();
- }
- /**
- * 注册服务
- *
- * @return void
- */
- protected function registerServices()
- {
- // 注册OpenAPI服务
- $this->app->singleton('openapi.service', function () {
- return new \App\Module\OpenAPI\Services\OpenApiService();
- });
- // 注册认证服务
- $this->app->singleton('openapi.auth', function ($app) {
- return new \App\Module\OpenAPI\Services\AuthService(
- $app->make('openapi.service')
- );
- });
- }
- /**
- * 注册事件监听器
- *
- * @return void
- */
- protected function registerEventListeners()
- {
- Event::listen(
- AppCreatedEvent::class,
- AppCreatedListener::class
- );
- }
- /**
- * 获取提供的服务
- *
- * @return array
- */
- public function provides()
- {
- return [
- 'openapi.service',
- 'openapi.auth',
- ];
- }
- }
|