|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Providers; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Database\MigrationServiceProvider as IlluminateMigrationServiceProvider; |
|
8
|
|
|
use LaravelFreelancerNL\Aranguent\Console\Migrations\AranguentConvertMigrationsCommand; |
|
9
|
|
|
use LaravelFreelancerNL\Aranguent\Console\Migrations\MigrateMakeCommand; |
|
10
|
|
|
use LaravelFreelancerNL\Aranguent\Console\ModelMakeCommand; |
|
11
|
|
|
use LaravelFreelancerNL\Aranguent\Migrations\DatabaseMigrationRepository; |
|
12
|
|
|
use LaravelFreelancerNL\Aranguent\Migrations\MigrationCreator; |
|
13
|
|
|
|
|
14
|
|
|
class CommandServiceProvider extends IlluminateMigrationServiceProvider |
|
15
|
|
|
{ |
|
16
|
|
|
protected bool $defer = true; |
|
17
|
|
|
|
|
18
|
310 |
|
public function boot(): void |
|
19
|
|
|
{ |
|
20
|
310 |
|
if ($this->app->runningInConsole()) { |
|
21
|
310 |
|
$this->commands([ |
|
22
|
310 |
|
MigrateMakeCommand::class, |
|
23
|
310 |
|
ModelMakeCommand::class, |
|
24
|
310 |
|
]); |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Register the service provider. |
|
30
|
|
|
* |
|
31
|
|
|
* @return void |
|
32
|
|
|
*/ |
|
33
|
310 |
|
public function register() |
|
34
|
|
|
{ |
|
35
|
310 |
|
$this->registerRepository(); |
|
36
|
|
|
|
|
37
|
310 |
|
$this->registerMigrator(); |
|
38
|
|
|
|
|
39
|
310 |
|
$this->registerCreator(); |
|
40
|
|
|
|
|
41
|
310 |
|
$commands = array_merge( |
|
42
|
310 |
|
$this->commands, |
|
43
|
310 |
|
[ |
|
44
|
310 |
|
'AranguentConvertMigrations' => 'command.aranguent.convert-migrations', |
|
45
|
310 |
|
'MigrateMake' => 'command.migrate.make', |
|
46
|
310 |
|
'ModelMake' => 'command.model.aranguent', |
|
47
|
310 |
|
] |
|
48
|
310 |
|
); |
|
49
|
310 |
|
$this->registerCommands($commands); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
310 |
|
protected function registerRepository() |
|
56
|
|
|
{ |
|
57
|
310 |
|
$this->app->singleton('migration.repository', function ($app) { |
|
58
|
310 |
|
$collection = $app['config']['database.migrations']; |
|
59
|
|
|
|
|
60
|
310 |
|
return new DatabaseMigrationRepository($app['db'], $collection); |
|
61
|
310 |
|
}); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
310 |
|
protected function registerCreator() |
|
65
|
|
|
{ |
|
66
|
310 |
|
$this->app->singleton('migration.creator', function ($app) { |
|
67
|
310 |
|
$customStubPath = __DIR__ . '/../../stubs'; |
|
68
|
|
|
|
|
69
|
310 |
|
return new MigrationCreator($app['files'], $customStubPath); |
|
70
|
310 |
|
}); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Register the command. |
|
75
|
|
|
* |
|
76
|
|
|
* @return void |
|
77
|
|
|
*/ |
|
78
|
310 |
|
protected function registerMigrateMakeCommand() |
|
79
|
|
|
{ |
|
80
|
310 |
|
$this->app->singleton('command.migrate.make', function ($app) { |
|
81
|
310 |
|
$creator = $app['migration.creator']; |
|
82
|
|
|
|
|
83
|
310 |
|
$composer = $app['composer']; |
|
84
|
|
|
|
|
85
|
310 |
|
return new MigrateMakeCommand($creator, $composer); |
|
86
|
310 |
|
}); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
310 |
|
protected function registerModelMakeCommand(): void |
|
90
|
|
|
{ |
|
91
|
310 |
|
$this->app->singleton('command.model.aranguent', function ($app) { |
|
92
|
310 |
|
return new ModelMakeCommand($app['files']); |
|
93
|
310 |
|
}); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
310 |
|
protected function registerAranguentConvertMigrationsCommand(): void |
|
97
|
|
|
{ |
|
98
|
310 |
|
$this->app->singleton('command.aranguent.convert-migrations', function ($app) { |
|
99
|
310 |
|
return new AranguentConvertMigrationsCommand($app['migrator']); |
|
100
|
310 |
|
}); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return string[] |
|
105
|
|
|
*/ |
|
106
|
|
|
public function provides() |
|
107
|
|
|
{ |
|
108
|
|
|
return [ |
|
109
|
|
|
'migrator', |
|
110
|
|
|
'migration.creator', |
|
111
|
|
|
'migration.repository', |
|
112
|
|
|
'command.aranguent.convert-migrations', |
|
113
|
|
|
'command.migrate.make', |
|
114
|
|
|
'command.model.aranguent', |
|
115
|
|
|
]; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|