| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- namespace App\Module\Point\Providers;
- use Illuminate\Support\ServiceProvider;
- /**
- * 积分模块服务提供者
- *
- * 负责注册积分模块的服务、配置和路由
- */
- class PointServiceProvider extends ServiceProvider
- {
- /**
- * 注册服务
- *
- * @return void
- */
- public function register()
- {
- // 注册积分服务
- $this->app->singleton('point.service', function ($app) {
- return new \App\Module\Point\Services\PointService(0, 0);
- });
- // 注册积分账户服务
- $this->app->singleton('point.account.service', function ($app) {
- return new \App\Module\Point\Services\AccountService();
- });
- // 注册积分类型服务
- $this->app->singleton('point.currency.service', function ($app) {
- return new \App\Module\Point\Services\CurrencyService();
- });
- // 注册积分日志服务
- $this->app->singleton('point.log.service', function ($app) {
- return new \App\Module\Point\Services\LogService();
- });
- }
- /**
- * 启动服务
- *
- * @return void
- */
- public function boot()
- {
- // 加载路由
- $this->loadRoutes();
- // 加载视图
- $this->loadViews();
- // 加载配置
- $this->loadConfigs();
- // 发布资源
- $this->publishResources();
- }
- /**
- * 加载路由
- *
- * @return void
- */
- protected function loadRoutes()
- {
- // 加载API路由
- if (file_exists($apiRoutes = __DIR__ . '/../routes/api.php')) {
- $this->loadRoutesFrom($apiRoutes);
- }
- // 加载Web路由
- if (file_exists($webRoutes = __DIR__ . '/../routes/web.php')) {
- $this->loadRoutesFrom($webRoutes);
- }
- // 加载后台路由
- if (file_exists($adminRoutes = __DIR__ . '/../routes/admin.php')) {
- $this->loadRoutesFrom($adminRoutes);
- }
- }
- /**
- * 加载视图
- *
- * @return void
- */
- protected function loadViews()
- {
- $viewPath = __DIR__ . '/../resources/views';
- if (is_dir($viewPath)) {
- $this->loadViewsFrom($viewPath, 'point');
- }
- }
- /**
- * 加载配置
- *
- * @return void
- */
- protected function loadConfigs()
- {
- $configPath = __DIR__ . '/../config';
- if (is_dir($configPath)) {
- $configs = glob($configPath . '/*.php');
- foreach ($configs as $config) {
- $name = 'point.' . basename($config, '.php');
- $this->mergeConfigFrom($config, $name);
- }
- }
- }
- /**
- * 发布资源
- *
- * @return void
- */
- protected function publishResources()
- {
- // 发布配置文件
- $configPath = __DIR__ . '/../config';
- if (is_dir($configPath)) {
- $this->publishes([
- $configPath => config_path('point'),
- ], 'point-config');
- }
- // 发布数据库迁移文件
- $migrationPath = __DIR__ . '/../database/migrations';
- if (is_dir($migrationPath)) {
- $this->publishes([
- $migrationPath => database_path('migrations'),
- ], 'point-migrations');
- }
- // 发布视图文件
- $viewPath = __DIR__ . '/../resources/views';
- if (is_dir($viewPath)) {
- $this->publishes([
- $viewPath => resource_path('views/vendor/point'),
- ], 'point-views');
- }
- // 发布前端资源
- $assetsPath = __DIR__ . '/../resources/assets';
- if (is_dir($assetsPath)) {
- $this->publishes([
- $assetsPath => public_path('vendor/point'),
- ], 'point-assets');
- }
- }
- /**
- * 获取提供的服务
- *
- * @return array
- */
- public function provides()
- {
- return [
- 'point.service',
- 'point.account.service',
- 'point.currency.service',
- 'point.log.service',
- ];
- }
- }
|