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