1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelZero\Framework\Commands\Component\Illuminate\Database; |
4
|
|
|
|
5
|
|
|
use LaravelZero\Framework\Commands\Component\AbstractComponentProvider; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* This is the Laravel Zero Framework illuminate/database component provider class. |
9
|
|
|
* |
10
|
|
|
* @author Nuno Maduro <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class ComponentProvider extends AbstractComponentProvider |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* {@inheritdoc} |
16
|
|
|
*/ |
17
|
|
|
public function isAvailable(): bool |
18
|
|
|
{ |
19
|
|
|
return class_exists(\Illuminate\Database\DatabaseServiceProvider::class); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
|
public function register(): void |
26
|
|
|
{ |
27
|
|
|
if (file_exists(config_path('database.php'))) { |
28
|
|
|
$this->mergeConfigFrom(config_path('database.php'), 'database'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$this->registerDatabaseService(); |
32
|
|
|
|
33
|
|
|
$this->registerMigrationService(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Registers the database service. |
38
|
|
|
* |
39
|
|
|
* Makes this Capsule instance available globally via static methods. |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
protected function registerDatabaseService(): void |
44
|
|
|
{ |
45
|
|
|
$this->registerServiceProvider(\Illuminate\Database\DatabaseServiceProvider::class); |
46
|
|
|
|
47
|
|
|
$this->app->alias('db', \Illuminate\Database\DatabaseManager::class); |
48
|
|
|
$this->app->alias('db', \Illuminate\Database\ConnectionResolverInterface::class); |
49
|
|
|
$this->app->alias('db.connection', \Illuminate\Database\DatabaseManager::class); |
50
|
|
|
$this->app->alias('db.connection', \Illuminate\Database\ConnectionInterface::class); |
51
|
|
|
|
52
|
|
|
$this->app->make(\Illuminate\Database\Capsule\Manager::class) |
53
|
|
|
->setAsGlobal(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Registers the migration service. |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
protected function registerMigrationService(): void |
62
|
|
|
{ |
63
|
|
|
$config = $this->app->make('config'); |
64
|
|
|
$config->set('database.migrations', $config->get('database.migrations') ?: 'migrations'); |
65
|
|
|
$this->registerServiceProvider(\Illuminate\Database\MigrationServiceProvider::class); |
66
|
|
|
$this->app->alias('migration.repository', \Illuminate\Database\Migrations\MigrationRepositoryInterface::class); |
67
|
|
|
|
68
|
|
|
if ($this->app->make('config') |
69
|
|
|
->get('database.with-migrations')) { |
70
|
|
|
$this->commands( |
71
|
|
|
[ |
72
|
|
|
\Illuminate\Database\Console\Migrations\FreshCommand::class, |
73
|
|
|
\Illuminate\Database\Console\Migrations\InstallCommand::class, |
74
|
|
|
\Illuminate\Database\Console\Migrations\MigrateCommand::class, |
75
|
|
|
\Illuminate\Database\Console\Migrations\MigrateMakeCommand::class, |
76
|
|
|
\Illuminate\Database\Console\Migrations\RefreshCommand::class, |
77
|
|
|
\Illuminate\Database\Console\Migrations\ResetCommand::class, |
78
|
|
|
\Illuminate\Database\Console\Migrations\RollbackCommand::class, |
79
|
|
|
\Illuminate\Database\Console\Migrations\StatusCommand::class, |
80
|
|
|
] |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|