MigrationServiceProvider.php 2.1KB

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