| 1 | <?php |
||
| 2 | |||
| 3 | namespace Werk365\JwtAuthRoles; |
||
| 4 | |||
| 5 | use Illuminate\Filesystem\Filesystem; |
||
| 6 | use Illuminate\Routing\Router; |
||
| 7 | use Illuminate\Support\Collection; |
||
| 8 | use Illuminate\Support\ServiceProvider; |
||
| 9 | use Werk365\JwtAuthRoles\Middlewares\RoleMiddleware; |
||
| 10 | |||
| 11 | class JwtAuthRolesServiceProvider extends ServiceProvider |
||
| 12 | { |
||
| 13 | public function boot(Filesystem $filesystem) |
||
| 14 | { |
||
| 15 | // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'werk365'); |
||
| 16 | // $this->loadViewsFrom(__DIR__.'/../resources/views', 'werk365'); |
||
| 17 | // $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); |
||
| 18 | // $this->loadRoutesFrom(__DIR__.'/routes.php'); |
||
| 19 | |||
| 20 | // Publishing is only necessary when using the CLI. |
||
| 21 | if ($this->app->runningInConsole()) { |
||
| 22 | $this->bootForConsole(); |
||
| 23 | } |
||
| 24 | |||
| 25 | $router = $this->app->make(Router::class); |
||
| 26 | $router->aliasMiddleware('role', RoleMiddleware::class); |
||
| 27 | |||
| 28 | if (function_exists('config_path')) { // function not available and 'publish' not relevant in Lumen |
||
| 29 | $this->publishes([ |
||
| 30 | __DIR__.'/../config/jwtauthroles.php' => config_path('jwtauthroles.php'), |
||
| 31 | ], 'config'); |
||
| 32 | |||
| 33 | $this->publishes([ |
||
| 34 | __DIR__.'/../database/migrations/create_jwtauth_tables.php.stub' => $this->getMigrationFileName($filesystem), |
||
| 35 | ], 'migrations'); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Register any package services. |
||
| 41 | * |
||
| 42 | * @return void |
||
| 43 | */ |
||
| 44 | public function register() |
||
| 45 | { |
||
| 46 | $this->mergeConfigFrom(__DIR__.'/../config/jwtauthroles.php', 'jwtauthroles'); |
||
| 47 | |||
| 48 | // Register the service the package provides. |
||
| 49 | $this->app->singleton('JwtAuthRoles', function ($app) { |
||
|
0 ignored issues
–
show
|
|||
| 50 | return new JwtAuthRoles; |
||
| 51 | }); |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Get the services provided by the provider. |
||
| 56 | * |
||
| 57 | * @return array |
||
| 58 | */ |
||
| 59 | public function provides() |
||
| 60 | { |
||
| 61 | return ['JwtAuthRoles']; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Console-specific booting. |
||
| 66 | * |
||
| 67 | * @return void |
||
| 68 | */ |
||
| 69 | protected function bootForConsole() |
||
| 70 | { |
||
| 71 | // Publishing the configuration file. |
||
| 72 | $this->publishes([ |
||
| 73 | __DIR__.'/../config/jwtauthroles.php' => config_path('jwtauthroles.php'), |
||
| 74 | ], 'jwtauthroles.config'); |
||
| 75 | |||
| 76 | // Publishing the views. |
||
| 77 | /*$this->publishes([ |
||
| 78 | __DIR__.'/../resources/views' => base_path('resources/views/vendor/werk365'), |
||
| 79 | ], 'jwtAuthRoles.views');*/ |
||
| 80 | |||
| 81 | // Publishing assets. |
||
| 82 | /*$this->publishes([ |
||
| 83 | __DIR__.'/../resources/assets' => public_path('vendor/werk365'), |
||
| 84 | ], 'jwtAuthRoles.views');*/ |
||
| 85 | |||
| 86 | // Publishing the translation files. |
||
| 87 | /*$this->publishes([ |
||
| 88 | __DIR__.'/../resources/lang' => resource_path('lang/vendor/werk365'), |
||
| 89 | ], 'jwtAuthRoles.views');*/ |
||
| 90 | |||
| 91 | // Registering package commands. |
||
| 92 | // $this->commands([]); |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Returns existing migration file if found, else uses the current timestamp. |
||
| 97 | * |
||
| 98 | * @param Filesystem $filesystem |
||
| 99 | * @return string |
||
| 100 | */ |
||
| 101 | protected function getMigrationFileName(Filesystem $filesystem): string |
||
| 102 | { |
||
| 103 | $timestamp = date('Y_m_d_His'); |
||
| 104 | |||
| 105 | return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) |
||
| 106 | ->flatMap(function ($path) use ($filesystem) { |
||
| 107 | return $filesystem->glob($path.'*_create_jwtauth_tables.php'); |
||
| 108 | })->push($this->app->databasePath()."/migrations/{$timestamp}_create_jwtauth_tables.php") |
||
| 109 | ->first(); |
||
| 110 | } |
||
| 111 | } |
||
| 112 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.