|
1
|
|
|
<?php |
|
2
|
|
|
namespace Elimuswift\DbExporter; |
|
3
|
|
|
|
|
4
|
|
|
use Illuminate\Support\ServiceProvider; |
|
5
|
|
|
use Illuminate\Support\Facades\Config; |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
class DbExportHandlerServiceProvider extends ServiceProvider |
|
9
|
|
|
{ |
|
10
|
|
|
protected $defer = false; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var DbMigrations $migrator |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $migrator; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var DbSeeding $seeder |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $seeder; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var DbExportHandler $handler |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $handler; |
|
25
|
|
|
|
|
26
|
|
|
public function boot(DbMigrations $migrator) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->publishes([ |
|
29
|
|
|
realpath(__DIR__ .'/../').'/config/db-exporter.php' => config_path('db-exporter.php'), |
|
30
|
|
|
]); |
|
31
|
|
|
|
|
32
|
|
|
$this->mergeConfigFrom( |
|
33
|
|
|
realpath(__DIR__ .'/../').'/config/db-exporter.php', 'db-exporter' |
|
34
|
|
|
); |
|
35
|
|
|
// Instatiate a new DbMigrations class to send to the handler |
|
36
|
|
|
$this->migrator = $migrator; |
|
37
|
|
|
// Load the alias |
|
38
|
|
|
$this->loadAlias(); |
|
39
|
|
|
// Handle the artisan commands |
|
40
|
|
|
$this->registerCommands(); |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function register() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->app->register(DbMigrationsServiceProvider::class); |
|
48
|
|
|
// Register the base export handler class |
|
49
|
|
|
$this->registerDbExportHandler(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function provides() |
|
53
|
|
|
{ |
|
54
|
|
|
return array('DbExporter'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Register the needed commands |
|
59
|
|
|
*/ |
|
60
|
|
|
public function registerCommands() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->registerMigrationsCommand(); |
|
63
|
|
|
$this->registerSeedsCommand(); |
|
64
|
|
|
$this->registerRemoteCommand(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Register the migrations command |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function registerMigrationsCommand() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->app->bind('db-exporter:migrations', function($app) |
|
73
|
|
|
{ |
|
74
|
|
|
return new Commands\MigrationsGeneratorCommand($app[DbExportHandler::class]); |
|
75
|
|
|
}); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Register the seeds command |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function registerSeedsCommand() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->app->bind('db-exporter:seeds', function($app) |
|
84
|
|
|
{ |
|
85
|
|
|
return new Commands\SeedGeneratorCommand($app[DbExportHandler::class]); |
|
86
|
|
|
}); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
protected function registerRemoteCommand() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->app->bind('db-exporter:backup', function() |
|
92
|
|
|
{ |
|
93
|
|
|
return new Commands\CopyToRemoteCommand(new Server); |
|
94
|
|
|
}); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Register the Export handler class |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function registerDbExportHandler() |
|
101
|
|
|
{ |
|
102
|
|
|
$this->app->bind(DbExportHandler::class, function($app) |
|
103
|
|
|
{ |
|
104
|
|
|
// Instatiate a new DbSeeding class to send to the handler |
|
105
|
|
|
$seeder = new DbSeeding($app[DbMigrations::class]->database); |
|
106
|
|
|
|
|
107
|
|
|
// Instantiate the handler |
|
108
|
|
|
return new DbExportHandler($app[DbMigrations::class], $seeder); |
|
109
|
|
|
}); |
|
110
|
|
|
|
|
111
|
|
|
$this->app->bind('DbExporter', function($app){ |
|
112
|
|
|
return $app[DbExportHandler::class]; |
|
113
|
|
|
}); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Load the alias = One less install step for the user |
|
118
|
|
|
*/ |
|
119
|
|
|
protected function loadAlias() |
|
120
|
|
|
{ |
|
121
|
|
|
|
|
122
|
|
|
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); |
|
123
|
|
|
$loader->alias('DbExporter', Facades\DbExportHandler::class); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
} |