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