Codexshaper /
laravel-database-manager
| 1 | <?php |
||
| 2 | |||
| 3 | namespace CodexShaper\DBM; |
||
| 4 | |||
| 5 | use CodexShaper\DBM\Commands\DatabaseAdmin; |
||
| 6 | use CodexShaper\DBM\Commands\DatabaseBackup; |
||
| 7 | use CodexShaper\DBM\Commands\DatabaseRestore; |
||
| 8 | use CodexShaper\DBM\Commands\DatabaseSeed; |
||
| 9 | use CodexShaper\DBM\Commands\InstallDatabaseManager; |
||
| 10 | use CodexShaper\DBM\MongoDB\Passport\AuthCode; |
||
| 11 | use CodexShaper\DBM\MongoDB\Passport\Bridge\RefreshToken; |
||
| 12 | use CodexShaper\DBM\MongoDB\Passport\Bridge\RefreshTokenRepository; |
||
| 13 | use CodexShaper\DBM\MongoDB\Passport\Client; |
||
| 14 | use CodexShaper\DBM\MongoDB\Passport\PersonalAccessClient; |
||
| 15 | use CodexShaper\DBM\MongoDB\Passport\Token; |
||
| 16 | use CodexShaper\Dumper\Contracts\Dumper; |
||
| 17 | use CodexShaper\Dumper\Drivers\MongoDumper; |
||
| 18 | use CodexShaper\Dumper\Drivers\MysqlDumper; |
||
| 19 | use CodexShaper\Dumper\Drivers\PgsqlDumper; |
||
| 20 | use CodexShaper\Dumper\Drivers\SqliteDumper; |
||
| 21 | use Illuminate\Support\ServiceProvider; |
||
| 22 | |||
| 23 | class ManagerServiceProvider extends ServiceProvider |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Boot the service provider. |
||
| 27 | * |
||
| 28 | * @return void |
||
| 29 | */ |
||
| 30 | public function boot() |
||
| 31 | { |
||
| 32 | $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); |
||
| 33 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'dbm'); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Register the service provider. |
||
| 38 | * |
||
| 39 | * @return void |
||
| 40 | */ |
||
| 41 | public function register() |
||
| 42 | { |
||
| 43 | $database = $this->app->config['database']; |
||
| 44 | // Bind Dumper to backup and and restore |
||
| 45 | $this->app->bind(Dumper::class, function ($app) use ($database) { |
||
|
0 ignored issues
–
show
|
|||
| 46 | $connection = $database['default']; |
||
| 47 | $options = [ |
||
| 48 | 'host' => $database['connections'][$connection]['host'] ?? '', |
||
| 49 | 'port' => $database['connections'][$connection]['port'] ?? 3306, |
||
| 50 | 'dbName' => $database['connections'][$connection]['database'] ?? '', |
||
| 51 | 'username' => $database['connections'][$connection]['username'] ?? 'root', |
||
| 52 | 'password' => $database['connections'][$connection]['password'] ?? '', |
||
| 53 | ]; |
||
| 54 | switch ($connection) { |
||
| 55 | case 'mysql': |
||
| 56 | return new MysqlDumper($options); |
||
| 57 | break; |
||
|
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other Loading history...
|
|||
| 58 | case 'sqlite': |
||
| 59 | return new SqliteDumper($options); |
||
| 60 | break; |
||
| 61 | case 'pgsql': |
||
| 62 | return new PgsqlDumper($options); |
||
| 63 | break; |
||
| 64 | case 'mongodb': |
||
| 65 | return new MongoDumper($options); |
||
| 66 | break; |
||
| 67 | } |
||
| 68 | }); |
||
| 69 | // Register aliases for mongoDB passport |
||
| 70 | if ($database['default'] == 'mongodb') { |
||
| 71 | if (class_exists('Illuminate\Foundation\AliasLoader')) { |
||
| 72 | $loader = \Illuminate\Foundation\AliasLoader::getInstance(); |
||
| 73 | $loader->alias('Laravel\Passport\AuthCode', AuthCode::class); |
||
| 74 | $loader->alias('Laravel\Passport\Client', Client::class); |
||
| 75 | $loader->alias('Laravel\Passport\Bridge\RefreshTokenRepository', RefreshTokenRepository::class); |
||
| 76 | $loader->alias('Laravel\Passport\Bridge\RefreshToken', RefreshToken::class); |
||
| 77 | $loader->alias('Laravel\Passport\PersonalAccessClient', PersonalAccessClient::class); |
||
| 78 | $loader->alias('Laravel\Passport\Token', Token::class); |
||
| 79 | } else { |
||
| 80 | class_alias('Laravel\Passport\AuthCode', AuthCode::class); |
||
| 81 | class_alias('Laravel\Passport\Client', Client::class); |
||
| 82 | class_alias('Laravel\Passport\Bridge\RefreshTokenRepository', RefreshTokenRepository::class); |
||
| 83 | class_alias('Laravel\Passport\Bridge\RefreshToken', RefreshToken::class); |
||
| 84 | class_alias('Laravel\Passport\PersonalAccessClient', PersonalAccessClient::class); |
||
| 85 | class_alias('Laravel\Passport\Token', Token::class); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | $this->mergeConfigFrom( |
||
| 90 | __DIR__.'/../config/dbm.php', 'config' |
||
| 91 | ); |
||
| 92 | $this->loadHelpers(); |
||
| 93 | $this->registerPublish(); |
||
| 94 | $this->registerCommands(); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Include helper files. |
||
| 99 | * |
||
| 100 | * @return void |
||
| 101 | */ |
||
| 102 | protected function loadHelpers() |
||
| 103 | { |
||
| 104 | foreach (glob(__DIR__.'/Helpers/*.php') as $filename) { |
||
| 105 | require_once $filename; |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Register the publishers. |
||
| 111 | * |
||
| 112 | * @return void |
||
| 113 | */ |
||
| 114 | protected function registerPublish() |
||
| 115 | { |
||
| 116 | $publishable = [ |
||
| 117 | 'dbm.config' => [ |
||
| 118 | __DIR__.'/../config/dbm.php' => config_path('dbm.php'), |
||
| 119 | ], |
||
| 120 | 'dbm.migrations' => [ |
||
| 121 | __DIR__.'/../database/migrations/' => database_path('migrations'), |
||
| 122 | ], |
||
| 123 | 'dbm.seeds' => [ |
||
| 124 | __DIR__.'/../database/seeds/' => database_path('seeds'), |
||
| 125 | ], |
||
| 126 | 'dbm.views' => [ |
||
| 127 | __DIR__.'/../resources/views' => resource_path('views/vendor/dbm/views'), |
||
| 128 | ], |
||
| 129 | 'dbm.resources' => [ |
||
| 130 | __DIR__.'/../resources' => resource_path('views/vendor/dbm'), |
||
| 131 | ], |
||
| 132 | ]; |
||
| 133 | |||
| 134 | foreach ($publishable as $group => $paths) { |
||
| 135 | $this->publishes($paths, $group); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Register commands. |
||
| 141 | * |
||
| 142 | * @return void |
||
| 143 | */ |
||
| 144 | private function registerCommands() |
||
| 145 | { |
||
| 146 | $this->commands(InstallDatabaseManager::class); |
||
| 147 | $this->commands(DatabaseAdmin::class); |
||
| 148 | $this->commands(DatabaseBackup::class); |
||
| 149 | $this->commands(DatabaseRestore::class); |
||
| 150 | $this->commands(DatabaseSeed::class); |
||
| 151 | } |
||
| 152 | } |
||
| 153 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.