MigrationServiceProvider.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace Illuminate\Database;
  3. use Illuminate\Support\ServiceProvider;
  4. use Illuminate\Database\Migrations\Migrator;
  5. use Illuminate\Contracts\Support\DeferrableProvider;
  6. use Illuminate\Database\Migrations\MigrationCreator;
  7. use Illuminate\Database\Migrations\DatabaseMigrationRepository;
  8. class MigrationServiceProvider extends ServiceProvider implements DeferrableProvider
  9. {
  10. /**
  11. * Register the service provider.
  12. *
  13. * @return void
  14. */
  15. public function register()
  16. {
  17. $this->registerRepository();
  18. $this->registerMigrator();
  19. $this->registerCreator();
  20. }
  21. /**
  22. * Register the migration repository service.
  23. *
  24. * @return void
  25. */
  26. protected function registerRepository()
  27. {
  28. $this->app->singleton('migration.repository', function ($app) {
  29. $table = $app['config']['database.migrations'];
  30. return new DatabaseMigrationRepository($app['db'], $table);
  31. });
  32. }
  33. /**
  34. * Register the migrator service.
  35. *
  36. * @return void
  37. */
  38. protected function registerMigrator()
  39. {
  40. // The migrator is responsible for actually running and rollback the migration
  41. // files in the application. We'll pass in our database connection resolver
  42. // so the migrator can resolve any of these connections when it needs to.
  43. $this->app->singleton('migrator', function ($app) {
  44. $repository = $app['migration.repository'];
  45. return new Migrator($repository, $app['db'], $app['files'], $app['events']);
  46. });
  47. }
  48. /**
  49. * Register the migration creator.
  50. *
  51. * @return void
  52. */
  53. protected function registerCreator()
  54. {
  55. $this->app->singleton('migration.creator', function ($app) {
  56. return new MigrationCreator($app['files']);
  57. });
  58. }
  59. /**
  60. * Get the services provided by the provider.
  61. *
  62. * @return array
  63. */
  64. public function provides()
  65. {
  66. return [
  67. 'migrator', 'migration.repository', 'migration.creator',
  68. ];
  69. }
  70. }