thinkstudeo /
laravel-rakshak
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Thinkstudeo\Rakshak; |
||
| 4 | |||
| 5 | use Illuminate\Foundation\AliasLoader; |
||
| 6 | use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; |
||
| 7 | use Illuminate\Support\Facades\Route; |
||
| 8 | use Thinkstudeo\Rakshak\Console\InstallCommand; |
||
| 9 | use Thinkstudeo\Rakshak\Console\PublishCommand; |
||
| 10 | use Thinkstudeo\Rakshak\Middleware\CheckRole; |
||
| 11 | use Thinkstudeo\Rakshak\Middleware\VerifyTwoFactorOtp; |
||
| 12 | use Thinkstudeo\Rakshak\Support\BladeDirectives; |
||
| 13 | |||
| 14 | class RakshakServiceProvider extends ServiceProvider |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * The policy mappings for the application. |
||
| 18 | * |
||
| 19 | * @var array |
||
| 20 | */ |
||
| 21 | protected $policies = [ |
||
| 22 | \Thinkstudeo\Rakshak\Role::class => \Thinkstudeo\Rakshak\Policies\RolePolicy::class, |
||
| 23 | \Thinkstudeo\Rakshak\Ability::class => \Thinkstudeo\Rakshak\Policies\AbilityPolicy::class, |
||
| 24 | \Thinkstudeo\Rakshak\RakshakSetting::class => \Thinkstudeo\Rakshak\Policies\RakshakSettingPolicy::class, |
||
| 25 | ]; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Bootstrap any application services. |
||
| 29 | * |
||
| 30 | * @return void |
||
| 31 | */ |
||
| 32 | public function boot(): void |
||
| 33 | { |
||
| 34 | if ($this->app->runningInConsole()) { |
||
| 35 | $this->registerPublishes(); |
||
| 36 | } |
||
| 37 | |||
| 38 | $this->mergeConfig(); |
||
| 39 | $this->registerAliases(); |
||
| 40 | $this->registerPolicies(); |
||
| 41 | $this->registerRoutes(); |
||
| 42 | $this->loadViews(); |
||
| 43 | $this->loadMigrations(); |
||
| 44 | $this->loadCache(); |
||
| 45 | BladeDirectives::register(); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Register any application services. |
||
| 50 | * |
||
| 51 | * @return void |
||
| 52 | */ |
||
| 53 | public function register(): void |
||
| 54 | { |
||
| 55 | $this->mergeConfigFrom(__DIR__.'/../config/rakshak.php', 'rakshak'); |
||
| 56 | |||
| 57 | $this->commands([ |
||
| 58 | InstallCommand::class, |
||
| 59 | PublishCommand::class, |
||
| 60 | ]); |
||
| 61 | |||
| 62 | $this->registerMiddleware(); |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Merge the Rakshak default config options. |
||
| 67 | * |
||
| 68 | * @return void |
||
| 69 | */ |
||
| 70 | protected function mergeConfig(): void |
||
| 71 | { |
||
| 72 | if (! $this->app->configurationIsCached()) { |
||
| 73 | $this->mergeConfigFrom(__DIR__.'/../config/rakshak.php', 'rakshak'); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Register the aliases for the package. |
||
| 79 | * |
||
| 80 | * @return void |
||
| 81 | */ |
||
| 82 | protected function registerAliases() |
||
| 83 | { |
||
| 84 | AliasLoader::getInstance()->alias('Rakshak', Rakshak::class); |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Register the package middlewares. |
||
| 89 | * |
||
| 90 | * @return void |
||
| 91 | */ |
||
| 92 | protected function registerMiddleware() |
||
| 93 | { |
||
| 94 | Route::aliasMiddleware('rakshak.2fa', VerifyTwoFactorOtp::class); |
||
| 95 | Route::aliasMiddleware('role', CheckRole::class); |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Register the routes for the package. |
||
| 100 | * |
||
| 101 | * @return void |
||
| 102 | */ |
||
| 103 | protected function registerRoutes() |
||
| 104 | { |
||
| 105 | Rakshak::routes(); |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Map the directory to load the views for the package. |
||
| 110 | * |
||
| 111 | * @return void |
||
| 112 | */ |
||
| 113 | public function loadViews() |
||
| 114 | { |
||
| 115 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'rakshak'); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Load migrations for the package. |
||
| 120 | * |
||
| 121 | * @return void |
||
| 122 | */ |
||
| 123 | protected function loadMigrations() |
||
| 124 | { |
||
| 125 | if (env('APP_ENV') !== 'testing') { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 126 | $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Load the cache keys for the package. |
||
| 132 | * |
||
| 133 | * @return void |
||
| 134 | */ |
||
| 135 | protected function loadCache() |
||
| 136 | { |
||
| 137 | if (env('APP_ENV') !== 'testing') { |
||
|
0 ignored issues
–
show
|
|||
| 138 | Rakshak::loadCache(); |
||
| 139 | } |
||
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Register the publishable config and views for the package. |
||
| 144 | * |
||
| 145 | * @return void |
||
| 146 | */ |
||
| 147 | protected function registerPublishes() |
||
| 148 | { |
||
| 149 | $this->publishes([ |
||
| 150 | __DIR__.'/../resources/views' => resource_path('views/vendor/rakshak'), |
||
| 151 | ], 'views'); |
||
| 152 | |||
| 153 | $this->publishes([ |
||
| 154 | __DIR__.'/../config/rakshak.php' => config_path('rakshak.php'), |
||
| 155 | ], 'config'); |
||
| 156 | } |
||
| 157 | } |
||
| 158 |