|
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
|
47 |
|
public function isAvailable(): bool |
|
18
|
|
|
{ |
|
19
|
47 |
|
return class_exists(\Illuminate\Database\DatabaseServiceProvider::class); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
47 |
|
public function register(): void |
|
26
|
|
|
{ |
|
27
|
47 |
|
if (file_exists(config_path('database.php'))) { |
|
28
|
|
|
$this->mergeConfigFrom(config_path('database.php'), 'database'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
47 |
|
$this->registerDatabaseService(); |
|
32
|
|
|
|
|
33
|
47 |
|
$this->registerMigrationService(); |
|
34
|
47 |
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Registers the database service. |
|
38
|
|
|
* |
|
39
|
|
|
* Makes this Capsule instance available globally via static methods. |
|
40
|
|
|
* |
|
41
|
|
|
* @return void |
|
42
|
|
|
*/ |
|
43
|
47 |
|
protected function registerDatabaseService(): void |
|
44
|
|
|
{ |
|
45
|
47 |
|
$this->registerServiceProvider(\Illuminate\Database\DatabaseServiceProvider::class); |
|
46
|
|
|
|
|
47
|
47 |
|
$this->app->alias('db', \Illuminate\Database\DatabaseManager::class); |
|
48
|
47 |
|
$this->app->alias('db', \Illuminate\Database\ConnectionResolverInterface::class); |
|
49
|
47 |
|
$this->app->alias('db.connection', \Illuminate\Database\DatabaseManager::class); |
|
50
|
47 |
|
$this->app->alias('db.connection', \Illuminate\Database\ConnectionInterface::class); |
|
51
|
|
|
|
|
52
|
47 |
|
$this->app->make(\Illuminate\Database\Capsule\Manager::class) |
|
53
|
47 |
|
->setAsGlobal(); |
|
54
|
|
|
|
|
55
|
47 |
|
if ($this->app->make('config') |
|
56
|
47 |
|
->get('database.with-seeds', true)) { |
|
57
|
47 |
|
$this->commands( |
|
58
|
|
|
[ |
|
59
|
47 |
|
\Illuminate\Database\Console\Seeds\SeedCommand::class, |
|
60
|
|
|
\Illuminate\Database\Console\Seeds\SeederMakeCommand::class, |
|
61
|
|
|
] |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
47 |
|
if (is_dir(database_path('seeds'))) { |
|
65
|
14 |
|
collect( |
|
66
|
14 |
|
$this->app->make('files') |
|
67
|
14 |
|
->files(database_path('seeds')) |
|
68
|
14 |
|
)->each( |
|
69
|
14 |
|
function ($file) { |
|
70
|
|
|
$this->app->make('files') |
|
71
|
|
|
->requireOnce($file); |
|
72
|
14 |
|
} |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
47 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Registers the migration service. |
|
80
|
|
|
* |
|
81
|
|
|
* @return void |
|
82
|
|
|
*/ |
|
83
|
47 |
|
protected function registerMigrationService(): void |
|
84
|
|
|
{ |
|
85
|
47 |
|
$config = $this->app->make('config'); |
|
86
|
47 |
|
$config->set('database.migrations', $config->get('database.migrations') ?: 'migrations'); |
|
87
|
47 |
|
$this->registerServiceProvider(\Illuminate\Database\MigrationServiceProvider::class); |
|
88
|
47 |
|
$this->app->alias( |
|
89
|
47 |
|
'migration.repository', |
|
90
|
47 |
|
\Illuminate\Database\Migrations\MigrationRepositoryInterface::class |
|
91
|
|
|
); |
|
92
|
|
|
|
|
93
|
47 |
|
if ($this->app->make('config') |
|
94
|
47 |
|
->get('database.with-migrations', true)) { |
|
95
|
47 |
|
$this->commands( |
|
96
|
|
|
[ |
|
97
|
47 |
|
\Illuminate\Database\Console\Migrations\FreshCommand::class, |
|
98
|
|
|
\Illuminate\Database\Console\Migrations\InstallCommand::class, |
|
99
|
|
|
\Illuminate\Database\Console\Migrations\MigrateCommand::class, |
|
100
|
|
|
\Illuminate\Database\Console\Migrations\MigrateMakeCommand::class, |
|
101
|
|
|
\Illuminate\Database\Console\Migrations\RefreshCommand::class, |
|
102
|
|
|
\Illuminate\Database\Console\Migrations\ResetCommand::class, |
|
103
|
|
|
\Illuminate\Database\Console\Migrations\RollbackCommand::class, |
|
104
|
|
|
\Illuminate\Database\Console\Migrations\StatusCommand::class, |
|
105
|
|
|
] |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
47 |
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|