Capsule
2 years ago
Concerns
2 weeks ago
Connectors
2 weeks ago
Console
2 weeks ago
DBAL
2 weeks ago
Eloquent
2 weeks ago
Events
2 weeks ago
Migrations
2 weeks ago
PDO
2 weeks ago
Query
2 weeks ago
Schema
2 weeks ago
ClassMorphViolationException.php
2 years ago
ConfigurationUrlParser.php
2 years ago
Connection.php
2 weeks ago
ConnectionInterface.php
2 years ago
ConnectionResolver.php
2 weeks ago
ConnectionResolverInterface.php
2 years ago
DatabaseManager.php
2 weeks ago
DatabaseServiceProvider.php
2 weeks ago
DatabaseTransactionRecord.php
2 weeks ago
DatabaseTransactionsManager.php
2 weeks ago
DeadlockException.php
2 weeks ago
DetectsConcurrencyErrors.php
2 years ago
DetectsLostConnections.php
2 weeks ago
Grammar.php
2 weeks ago
LazyLoadingViolationException.php
2 years ago
LostConnectionException.php
2 weeks ago
MigrationServiceProvider.php
2 weeks ago
MultipleColumnsSelectedException.php
2 weeks ago
MultipleRecordsFoundException.php
2 weeks ago
MySqlConnection.php
2 weeks ago
PostgresConnection.php
2 weeks ago
QueryException.php
2 years ago
RecordsNotFoundException.php
2 years ago
SQLiteConnection.php
2 weeks ago
SQLiteDatabaseDoesNotExistException.php
2 weeks ago
Seeder.php
2 weeks ago
SqlServerConnection.php
2 weeks ago
MigrationServiceProvider.php
190 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWPSCOPED\Illuminate\Database; |
| 4 | |
| 5 | use IAWPSCOPED\Illuminate\Contracts\Events\Dispatcher; |
| 6 | use IAWPSCOPED\Illuminate\Contracts\Support\DeferrableProvider; |
| 7 | use IAWPSCOPED\Illuminate\Database\Console\Migrations\FreshCommand; |
| 8 | use IAWPSCOPED\Illuminate\Database\Console\Migrations\InstallCommand; |
| 9 | use IAWPSCOPED\Illuminate\Database\Console\Migrations\MigrateCommand; |
| 10 | use IAWPSCOPED\Illuminate\Database\Console\Migrations\MigrateMakeCommand; |
| 11 | use IAWPSCOPED\Illuminate\Database\Console\Migrations\RefreshCommand; |
| 12 | use IAWPSCOPED\Illuminate\Database\Console\Migrations\ResetCommand; |
| 13 | use IAWPSCOPED\Illuminate\Database\Console\Migrations\RollbackCommand; |
| 14 | use IAWPSCOPED\Illuminate\Database\Console\Migrations\StatusCommand; |
| 15 | use IAWPSCOPED\Illuminate\Database\Migrations\DatabaseMigrationRepository; |
| 16 | use IAWPSCOPED\Illuminate\Database\Migrations\MigrationCreator; |
| 17 | use IAWPSCOPED\Illuminate\Database\Migrations\Migrator; |
| 18 | use IAWPSCOPED\Illuminate\Support\ServiceProvider; |
| 19 | /** @internal */ |
| 20 | class MigrationServiceProvider extends ServiceProvider implements DeferrableProvider |
| 21 | { |
| 22 | /** |
| 23 | * The commands to be registered. |
| 24 | * |
| 25 | * @var array |
| 26 | */ |
| 27 | protected $commands = ['Migrate' => MigrateCommand::class, 'MigrateFresh' => FreshCommand::class, 'MigrateInstall' => InstallCommand::class, 'MigrateRefresh' => RefreshCommand::class, 'MigrateReset' => ResetCommand::class, 'MigrateRollback' => RollbackCommand::class, 'MigrateStatus' => StatusCommand::class, 'MigrateMake' => MigrateMakeCommand::class]; |
| 28 | /** |
| 29 | * Register the service provider. |
| 30 | * |
| 31 | * @return void |
| 32 | */ |
| 33 | public function register() |
| 34 | { |
| 35 | $this->registerRepository(); |
| 36 | $this->registerMigrator(); |
| 37 | $this->registerCreator(); |
| 38 | $this->registerCommands($this->commands); |
| 39 | } |
| 40 | /** |
| 41 | * Register the migration repository service. |
| 42 | * |
| 43 | * @return void |
| 44 | */ |
| 45 | protected function registerRepository() |
| 46 | { |
| 47 | $this->app->singleton('migration.repository', function ($app) { |
| 48 | $table = $app['config']['database.migrations']; |
| 49 | return new DatabaseMigrationRepository($app['db'], $table); |
| 50 | }); |
| 51 | } |
| 52 | /** |
| 53 | * Register the migrator service. |
| 54 | * |
| 55 | * @return void |
| 56 | */ |
| 57 | protected function registerMigrator() |
| 58 | { |
| 59 | // The migrator is responsible for actually running and rollback the migration |
| 60 | // files in the application. We'll pass in our database connection resolver |
| 61 | // so the migrator can resolve any of these connections when it needs to. |
| 62 | $this->app->singleton('migrator', function ($app) { |
| 63 | $repository = $app['migration.repository']; |
| 64 | return new Migrator($repository, $app['db'], $app['files'], $app['events']); |
| 65 | }); |
| 66 | } |
| 67 | /** |
| 68 | * Register the migration creator. |
| 69 | * |
| 70 | * @return void |
| 71 | */ |
| 72 | protected function registerCreator() |
| 73 | { |
| 74 | $this->app->singleton('migration.creator', function ($app) { |
| 75 | return new MigrationCreator($app['files'], $app->basePath('stubs')); |
| 76 | }); |
| 77 | } |
| 78 | /** |
| 79 | * Register the given commands. |
| 80 | * |
| 81 | * @param array $commands |
| 82 | * @return void |
| 83 | */ |
| 84 | protected function registerCommands(array $commands) |
| 85 | { |
| 86 | foreach (\array_keys($commands) as $command) { |
| 87 | $this->{"register{$command}Command"}(); |
| 88 | } |
| 89 | $this->commands(\array_values($commands)); |
| 90 | } |
| 91 | /** |
| 92 | * Register the command. |
| 93 | * |
| 94 | * @return void |
| 95 | */ |
| 96 | protected function registerMigrateCommand() |
| 97 | { |
| 98 | $this->app->singleton(MigrateCommand::class, function ($app) { |
| 99 | return new MigrateCommand($app['migrator'], $app[Dispatcher::class]); |
| 100 | }); |
| 101 | } |
| 102 | /** |
| 103 | * Register the command. |
| 104 | * |
| 105 | * @return void |
| 106 | */ |
| 107 | protected function registerMigrateFreshCommand() |
| 108 | { |
| 109 | $this->app->singleton(FreshCommand::class); |
| 110 | } |
| 111 | /** |
| 112 | * Register the command. |
| 113 | * |
| 114 | * @return void |
| 115 | */ |
| 116 | protected function registerMigrateInstallCommand() |
| 117 | { |
| 118 | $this->app->singleton(InstallCommand::class, function ($app) { |
| 119 | return new InstallCommand($app['migration.repository']); |
| 120 | }); |
| 121 | } |
| 122 | /** |
| 123 | * Register the command. |
| 124 | * |
| 125 | * @return void |
| 126 | */ |
| 127 | protected function registerMigrateMakeCommand() |
| 128 | { |
| 129 | $this->app->singleton(MigrateMakeCommand::class, function ($app) { |
| 130 | // Once we have the migration creator registered, we will create the command |
| 131 | // and inject the creator. The creator is responsible for the actual file |
| 132 | // creation of the migrations, and may be extended by these developers. |
| 133 | $creator = $app['migration.creator']; |
| 134 | $composer = $app['composer']; |
| 135 | return new MigrateMakeCommand($creator, $composer); |
| 136 | }); |
| 137 | } |
| 138 | /** |
| 139 | * Register the command. |
| 140 | * |
| 141 | * @return void |
| 142 | */ |
| 143 | protected function registerMigrateRefreshCommand() |
| 144 | { |
| 145 | $this->app->singleton(RefreshCommand::class); |
| 146 | } |
| 147 | /** |
| 148 | * Register the command. |
| 149 | * |
| 150 | * @return void |
| 151 | */ |
| 152 | protected function registerMigrateResetCommand() |
| 153 | { |
| 154 | $this->app->singleton(ResetCommand::class, function ($app) { |
| 155 | return new ResetCommand($app['migrator']); |
| 156 | }); |
| 157 | } |
| 158 | /** |
| 159 | * Register the command. |
| 160 | * |
| 161 | * @return void |
| 162 | */ |
| 163 | protected function registerMigrateRollbackCommand() |
| 164 | { |
| 165 | $this->app->singleton(RollbackCommand::class, function ($app) { |
| 166 | return new RollbackCommand($app['migrator']); |
| 167 | }); |
| 168 | } |
| 169 | /** |
| 170 | * Register the command. |
| 171 | * |
| 172 | * @return void |
| 173 | */ |
| 174 | protected function registerMigrateStatusCommand() |
| 175 | { |
| 176 | $this->app->singleton(StatusCommand::class, function ($app) { |
| 177 | return new StatusCommand($app['migrator']); |
| 178 | }); |
| 179 | } |
| 180 | /** |
| 181 | * Get the services provided by the provider. |
| 182 | * |
| 183 | * @return array |
| 184 | */ |
| 185 | public function provides() |
| 186 | { |
| 187 | return \array_merge(['migrator', 'migration.repository', 'migration.creator'], \array_values($this->commands)); |
| 188 | } |
| 189 | } |
| 190 |