1 | <?php |
||
2 | |||
3 | namespace Spinen\Halo\Providers; |
||
4 | |||
5 | use Illuminate\Support\Facades\Config; |
||
6 | use Illuminate\Support\Facades\Route; |
||
7 | use Illuminate\Support\ServiceProvider as LaravelServiceProvider; |
||
8 | use Spinen\Halo\Http\Middleware\Filter; |
||
9 | |||
10 | /** |
||
11 | * Class ServiceProvider |
||
12 | */ |
||
13 | class ServiceProvider extends LaravelServiceProvider |
||
14 | { |
||
15 | /** |
||
16 | * Bootstrap services. |
||
17 | * |
||
18 | * @return void |
||
19 | */ |
||
20 | public function boot() |
||
21 | { |
||
22 | $this->registerMiddleware(); |
||
23 | |||
24 | $this->registerPublishes(); |
||
25 | |||
26 | $this->registerRoutes(); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Register services. |
||
31 | * |
||
32 | * @return void |
||
33 | */ |
||
34 | public function register() |
||
35 | { |
||
36 | $this->mergeConfigFrom(__DIR__.'/../../config/halo.php', 'halo'); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Register the middleware |
||
41 | * |
||
42 | * If a route needs to have the QuickBooks client, then make sure that the user has linked their account. |
||
43 | */ |
||
44 | public function registerMiddleware() |
||
45 | { |
||
46 | $this->app->router->aliasMiddleware('halo', Filter::class); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
47 | } |
||
48 | |||
49 | /** |
||
50 | * There are several resources that get published |
||
51 | * |
||
52 | * Only worry about telling the application about them if running in the console. |
||
53 | */ |
||
54 | protected function registerPublishes() |
||
55 | { |
||
56 | if ($this->app->runningInConsole()) { |
||
57 | $this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); |
||
58 | |||
59 | $this->publishes( |
||
60 | groups: 'halo-config', |
||
61 | paths: [ |
||
62 | __DIR__.'/../../config/halo.php' => config_path('halo.php'), |
||
63 | ], |
||
64 | ); |
||
65 | |||
66 | $this->publishes( |
||
67 | groups: 'halo-migrations', |
||
68 | paths: [ |
||
69 | __DIR__.'/../../database/migrations' => database_path('migrations'), |
||
70 | ], |
||
71 | ); |
||
72 | } |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Register the routes needed for the OAuth flow |
||
77 | */ |
||
78 | protected function registerRoutes() |
||
79 | { |
||
80 | if (Config::get('halo.oauth.authorization_code.route.enabled')) { |
||
81 | Route::group( |
||
82 | attributes: [ |
||
83 | 'namespace' => 'Spinen\Halo\Http\Controllers', |
||
84 | 'middleware' => Config::get('halo.oauth.authorization_code.route.middleware', ['web']), |
||
85 | ], |
||
86 | routes: fn () => $this->loadRoutesFrom(realpath(__DIR__.'/../../routes/web.php')) |
||
87 | ); |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 |