|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Providers; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Database\Migrations\Migrator; |
|
8
|
|
|
use Illuminate\Database\MigrationServiceProvider as IlluminateMigrationServiceProvider; |
|
9
|
|
|
use LaravelFreelancerNL\Aranguent\Console\Concerns\ArangoCommands; |
|
10
|
|
|
use LaravelFreelancerNL\Aranguent\Console\Migrations\FreshCommand; |
|
11
|
|
|
use LaravelFreelancerNL\Aranguent\Console\Migrations\MigrationsConvertCommand; |
|
12
|
|
|
use LaravelFreelancerNL\Aranguent\Console\Migrations\MigrateMakeCommand; |
|
13
|
|
|
use LaravelFreelancerNL\Aranguent\Console\Migrations\MigrateInstallCommand; |
|
14
|
|
|
use LaravelFreelancerNL\Aranguent\Migrations\DatabaseMigrationRepository; |
|
15
|
|
|
use LaravelFreelancerNL\Aranguent\Migrations\MigrationCreator; |
|
16
|
|
|
|
|
17
|
|
|
class MigrationServiceProvider extends IlluminateMigrationServiceProvider |
|
18
|
|
|
{ |
|
19
|
|
|
use ArangoCommands; |
|
20
|
|
|
|
|
21
|
|
|
protected bool $defer = true; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string[] |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $aliases = [ |
|
27
|
|
|
'Migrator' => 'migrator', |
|
28
|
|
|
'Creator' => 'migration.creator', |
|
29
|
|
|
'Repository' => 'migration.repository', |
|
30
|
|
|
'MigrateMake' => 'migrate.make', |
|
31
|
|
|
'MigrateInstall' => MigrateInstallCommand::class, |
|
32
|
|
|
'MigrateFresh' => FreshCommand::class, |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Create a new service provider instance. |
|
37
|
|
|
* |
|
38
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
|
39
|
|
|
* @return void |
|
40
|
|
|
*/ |
|
41
|
498 |
|
public function __construct($app) |
|
42
|
|
|
{ |
|
43
|
498 |
|
parent::__construct($app); |
|
44
|
|
|
|
|
45
|
498 |
|
foreach ($this->aliases as $key => $alias) { |
|
46
|
498 |
|
$this->aliases[$key] = $alias; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
498 |
|
public function boot(): void |
|
51
|
|
|
{ |
|
52
|
498 |
|
if ($this->app->runningInConsole()) { |
|
53
|
498 |
|
$this->commands([ |
|
54
|
498 |
|
MigrateMakeCommand::class, |
|
55
|
498 |
|
MigrationsConvertCommand::class, |
|
56
|
498 |
|
FreshCommand::class, |
|
57
|
498 |
|
]); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Register the service provider. |
|
63
|
|
|
* |
|
64
|
|
|
* @return void |
|
65
|
|
|
*/ |
|
66
|
498 |
|
public function register() |
|
67
|
|
|
{ |
|
68
|
498 |
|
$this->registerRepository(); |
|
69
|
|
|
|
|
70
|
498 |
|
$this->registerMigrator(); |
|
71
|
|
|
|
|
72
|
498 |
|
$this->registerCreator(); |
|
73
|
|
|
|
|
74
|
498 |
|
$this->registerCommands($this->commands); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Register the migration repository service. |
|
79
|
|
|
* |
|
80
|
|
|
* @return void |
|
81
|
|
|
*/ |
|
82
|
498 |
|
protected function registerRepository() |
|
83
|
|
|
{ |
|
84
|
498 |
|
$this->app->singleton($this->aliases['Repository'], function ($app) { |
|
85
|
|
|
$table = $app['config']['database.migrations.table']; |
|
86
|
|
|
if (!$table) { |
|
87
|
|
|
$table = $app['config']['database.migrations']; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return new DatabaseMigrationRepository($app['db'], $table); |
|
91
|
498 |
|
}); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Register the migrator service. |
|
96
|
|
|
* |
|
97
|
|
|
* @return void |
|
98
|
|
|
*/ |
|
99
|
498 |
|
protected function registerMigrator() |
|
100
|
|
|
{ |
|
101
|
|
|
// The migrator is responsible for actually running and rollback the migration |
|
102
|
|
|
// files in the application. We'll pass in our database connection resolver |
|
103
|
|
|
// so the migrator can resolve any of these connections when it needs to. |
|
104
|
498 |
|
$this->app->singleton($this->aliases['Migrator'], function ($app) { |
|
105
|
|
|
$repository = $app[$this->aliases['Repository']]; |
|
106
|
|
|
|
|
107
|
|
|
return new Migrator($repository, $app['db'], $app['files'], $app['events']); |
|
108
|
498 |
|
}); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
498 |
|
protected function registerCreator() |
|
112
|
|
|
{ |
|
113
|
498 |
|
$this->app->singleton($this->aliases['Creator'], function ($app) { |
|
114
|
|
|
$customStubPath = __DIR__ . '/../Migrations/stubs'; |
|
115
|
|
|
|
|
116
|
|
|
return new MigrationCreator($app['files'], $customStubPath); |
|
117
|
498 |
|
}); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Register the command. |
|
122
|
|
|
* |
|
123
|
|
|
* @return void |
|
124
|
|
|
*/ |
|
125
|
498 |
|
protected function registerMigrateMakeCommand() |
|
126
|
|
|
{ |
|
127
|
|
|
|
|
128
|
498 |
|
$this->app->singleton($this->commands['MigrateMake'], function ($app) { |
|
129
|
|
|
$creator = $app['migration.creator']; |
|
130
|
|
|
|
|
131
|
|
|
$composer = $app['composer']; |
|
132
|
|
|
|
|
133
|
|
|
return new MigrateMakeCommand($creator, $composer); |
|
134
|
498 |
|
}); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Register the command. |
|
139
|
|
|
* |
|
140
|
|
|
* @return void |
|
141
|
|
|
*/ |
|
142
|
498 |
|
protected function registerMigrateInstallCommand() |
|
143
|
|
|
{ |
|
144
|
|
|
|
|
145
|
498 |
|
$this->app->singleton($this->commands['MigrateInstall'], function ($app) { |
|
146
|
|
|
$repository = $app[$this->aliases['Repository']]; |
|
147
|
|
|
|
|
148
|
|
|
return new MigrateInstallCommand($repository); |
|
149
|
498 |
|
}); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
protected function registerMigrationsConvertCommand(): void |
|
153
|
|
|
{ |
|
154
|
|
|
$this->app->singleton($this->commands['MigrationsConvert'], function ($app) { |
|
155
|
|
|
return new MigrationsConvertCommand($app['migrator']); |
|
156
|
|
|
}); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Register the command. |
|
161
|
|
|
* |
|
162
|
|
|
* @return void |
|
163
|
|
|
*/ |
|
164
|
498 |
|
protected function registerMigrateFreshCommand() |
|
165
|
|
|
{ |
|
166
|
498 |
|
$this->app->singleton(FreshCommand::class, function ($app) { |
|
167
|
498 |
|
return new FreshCommand($app['migrator']); |
|
168
|
498 |
|
}); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @return string[] |
|
173
|
|
|
*/ |
|
174
|
|
|
public function provides() |
|
175
|
|
|
{ |
|
176
|
|
|
return array_values($this->aliases); |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|