|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Elimuswift\DbExporter; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Config; |
|
6
|
|
|
use Illuminate\Foundation\AliasLoader; |
|
7
|
|
|
use Illuminate\Support\ServiceProvider; |
|
8
|
|
|
|
|
9
|
|
|
class DbExportHandlerServiceProvider extends ServiceProvider |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Defer loading of services provided by db-exporter. |
|
13
|
|
|
* |
|
14
|
|
|
* @var bool |
|
15
|
|
|
**/ |
|
16
|
|
|
protected $defer = true; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var DbMigrations |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $migrator; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var DbSeeding |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $seeder; |
|
27
|
|
|
/** |
|
28
|
|
|
* @var DbExportHandler |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $handler; |
|
31
|
|
|
|
|
32
|
|
|
public function boot(DbMigrations $migrator) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->publishes( |
|
35
|
|
|
[ |
|
36
|
|
|
realpath(__DIR__ . '/../') . '/config/db-exporter.php' => config_path('db-exporter.php'), |
|
37
|
|
|
], |
|
38
|
|
|
'config' |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
$this->mergeConfigFrom( |
|
42
|
|
|
realpath(__DIR__ . '/../') . '/config/db-exporter.php', |
|
43
|
|
|
'db-exporter' |
|
44
|
|
|
); |
|
45
|
|
|
// Instatiate a new DbMigrations class to send to the handler |
|
46
|
|
|
$this->migrator = $migrator; |
|
47
|
|
|
// Load the alias |
|
48
|
|
|
$this->loadAlias(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
//end boot() |
|
52
|
|
|
|
|
53
|
|
|
public function register() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->app->register(DbMigrationsServiceProvider::class); |
|
56
|
|
|
// Register the base export handler class |
|
57
|
|
|
$this->registerDbExportHandler(); |
|
58
|
|
|
// Handle the artisan commands |
|
59
|
|
|
$this->registerCommands(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
//end register() |
|
63
|
|
|
|
|
64
|
|
|
public function provides() |
|
65
|
|
|
{ |
|
66
|
|
|
return ['DbExporter']; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
//end provides() |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Register the needed commands. |
|
73
|
|
|
*/ |
|
74
|
|
|
public function registerCommands() |
|
75
|
|
|
{ |
|
76
|
|
|
$commands = [ |
|
77
|
|
|
'Migrations', |
|
78
|
|
|
'Seeds', |
|
79
|
|
|
'Backup', |
|
80
|
|
|
]; |
|
81
|
|
|
|
|
82
|
|
|
foreach ($commands as $command) { |
|
83
|
|
|
$this->{"register{$command}Command"}(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
// Once the commands are registered in the application IoC container we will |
|
87
|
|
|
// register them with the Artisan start event so that these are available |
|
88
|
|
|
// when the Artisan application actually starts up and is getting used. |
|
89
|
|
|
$this->commands('db-exporter.migrations', 'db-exporter.seeds', 'db-exporter.backup'); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
//end registerCommands() |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Register the migrations command. |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function registerMigrationsCommand() |
|
98
|
|
|
{ |
|
99
|
|
|
$this->app->singleton( |
|
100
|
|
|
'db-exporter.migrations', |
|
101
|
|
|
function($app) { |
|
102
|
|
|
return new Commands\MigrationsGeneratorCommand($app[DbExportHandler::class]); |
|
103
|
|
|
} |
|
104
|
|
|
); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
//end registerMigrationsCommand() |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Register the seeds command. |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function registerSeedsCommand() |
|
113
|
|
|
{ |
|
114
|
|
|
$this->app->singleton( |
|
115
|
|
|
'db-exporter.seeds', |
|
116
|
|
|
function($app) { |
|
117
|
|
|
return new Commands\SeedGeneratorCommand($app[DbExportHandler::class]); |
|
118
|
|
|
} |
|
119
|
|
|
); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
//end registerSeedsCommand() |
|
123
|
|
|
|
|
124
|
|
|
protected function registerBackupCommand() |
|
125
|
|
|
{ |
|
126
|
|
|
$this->app->singleton( |
|
127
|
|
|
'db-exporter.backup', |
|
128
|
|
|
function() { |
|
129
|
|
|
return new Commands\CopyToRemoteCommand(); |
|
130
|
|
|
} |
|
131
|
|
|
); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
//end registerBackupCommand() |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Register the Export handler class. |
|
138
|
|
|
*/ |
|
139
|
|
|
protected function registerDbExportHandler() |
|
140
|
|
|
{ |
|
141
|
|
|
$this->app->bind( |
|
142
|
|
|
DbExportHandler::class, |
|
143
|
|
|
function($app) { |
|
144
|
|
|
// Instatiate a new DbSeeding class to send to the handler |
|
145
|
|
|
$seeder = new DbSeeding($app[DbMigrations::class]->database); |
|
146
|
|
|
|
|
147
|
|
|
// Instantiate the handler |
|
148
|
|
|
return new DbExportHandler($app[DbMigrations::class], $seeder); |
|
149
|
|
|
} |
|
150
|
|
|
); |
|
151
|
|
|
|
|
152
|
|
|
$this->app->bind( |
|
153
|
|
|
'DbExporter', |
|
154
|
|
|
function($app) { |
|
155
|
|
|
return $app[DbExportHandler::class]; |
|
156
|
|
|
} |
|
157
|
|
|
); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
//end registerDbExportHandler() |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Load the alias = One less install step for the user. |
|
164
|
|
|
*/ |
|
165
|
|
|
protected function loadAlias() |
|
166
|
|
|
{ |
|
167
|
|
|
$loader = AliasLoader::getInstance(); |
|
168
|
|
|
$loader->alias('DbExporter', Facades\DbExportHandler::class); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
//end loadAlias() |
|
172
|
|
|
}//end class |
|
173
|
|
|
|