You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MigrationServiceProvider.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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']);
  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. }