|
1
|
|
|
<?php namespace KitLoong\MigrationsGenerator; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Container\Container; |
|
4
|
|
|
use Illuminate\Support\ServiceProvider; |
|
5
|
|
|
use KitLoong\MigrationsGenerator\Generators\Decorator; |
|
6
|
|
|
use Way\Generators\Compilers\Compiler; |
|
7
|
|
|
use Way\Generators\Compilers\TemplateCompiler; |
|
8
|
|
|
use KitLoong\MigrationsGenerator\Generators\SchemaGenerator; |
|
9
|
|
|
use Way\Generators\Generator; |
|
10
|
|
|
use Xethron\MigrationsGenerator\Syntax\AddForeignKeysToTable; |
|
11
|
|
|
use Xethron\MigrationsGenerator\Syntax\AddToTable; |
|
12
|
|
|
use Xethron\MigrationsGenerator\Syntax\RemoveForeignKeysFromTable; |
|
13
|
|
|
|
|
14
|
|
|
class MigrationsGeneratorServiceProvider extends ServiceProvider |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Indicates if loading of the provider is deferred. |
|
18
|
|
|
* |
|
19
|
|
|
* @var bool |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $defer = false; |
|
22
|
|
|
|
|
23
|
|
|
private const COMMAND = 'command.migration.generate'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Register the service provider. |
|
27
|
|
|
* |
|
28
|
|
|
* @return void |
|
29
|
|
|
*/ |
|
30
|
|
|
public function register() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->registerConfig(); |
|
33
|
|
|
|
|
34
|
|
|
$this->app->singleton( |
|
35
|
|
|
self::COMMAND, |
|
36
|
|
|
function (Container $app) { |
|
37
|
|
|
return new MigrateGenerateCommand( |
|
38
|
|
|
$app->make(Generator::class), |
|
39
|
|
|
$app->make(SchemaGenerator::class), |
|
40
|
|
|
$app->make('migration.repository'), |
|
41
|
|
|
$app->make(Decorator::class) |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
$this->commands(self::COMMAND); |
|
47
|
|
|
|
|
48
|
|
|
// Bind the Repository Interface to $app['migrations.repository'] |
|
49
|
|
|
$this->app->bind('Illuminate\Database\Migrations\MigrationRepositoryInterface', function ($app) { |
|
50
|
|
|
return $app['migration.repository']; |
|
51
|
|
|
}); |
|
52
|
|
|
|
|
53
|
|
|
$this->app->bind(AddForeignKeysToTable::class, AddForeignKeysToTable::class); |
|
54
|
|
|
$this->app->bind(AddToTable::class, AddToTable::class); |
|
55
|
|
|
$this->app->bind(RemoveForeignKeysFromTable::class, RemoveForeignKeysFromTable::class); |
|
56
|
|
|
|
|
57
|
|
|
$this->app->singleton(Compiler::class, TemplateCompiler::class); |
|
58
|
|
|
|
|
59
|
|
|
$this->app->singleton(MigrationsGeneratorSetting::class, function () { |
|
60
|
|
|
return new MigrationsGeneratorSetting(); |
|
61
|
|
|
}); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Bootstrap the application events. |
|
66
|
|
|
* |
|
67
|
|
|
* @return void |
|
68
|
|
|
*/ |
|
69
|
|
|
public function boot() |
|
70
|
|
|
{ |
|
71
|
|
|
// |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Register the config paths |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function registerConfig() |
|
78
|
|
|
{ |
|
79
|
|
|
$packageConfigFile = __DIR__.'/../../config/config.php'; |
|
80
|
|
|
$this->app->make('config')->set( |
|
81
|
|
|
'generators.config', |
|
82
|
|
|
$this->app->make('files')->getRequire($packageConfigFile) |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|