|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Schnittstabil\Dartisan\ServiceProviders; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Capsule\Manager as Capsule; |
|
6
|
|
|
use Illuminate\Database\Migrations\DatabaseMigrationRepository; |
|
7
|
|
|
use Illuminate\Database\Migrations\MigrationCreator; |
|
8
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
9
|
|
|
use Schnittstabil\Dartisan\Container; |
|
10
|
|
|
use Illuminate\Database\Migrations\Migrator; |
|
11
|
|
|
use Schnittstabil\Dartisan\OutputInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @SuppressWarnings(PHPMD.ShortVariable) |
|
15
|
|
|
*/ |
|
16
|
|
|
class DatabaseServiceProvider |
|
17
|
|
|
{ |
|
18
|
|
|
protected function setCapsule(Container $c) |
|
19
|
|
|
{ |
|
20
|
|
|
$c->set(Capsule::class, function (Container $c) { |
|
21
|
|
|
$capsule = new Capsule(); |
|
22
|
|
|
$capsule->addConnection($c->getNamespace('connection')); |
|
23
|
|
|
$capsule->bootEloquent(); |
|
24
|
|
|
$capsule->setAsGlobal(); |
|
25
|
|
|
|
|
26
|
|
|
return $capsule; |
|
27
|
|
|
}); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
protected function setDatabaseMigrationRepository(Container $c) |
|
31
|
|
|
{ |
|
32
|
|
|
$c->set(DatabaseMigrationRepository::class, function (Container $c) { |
|
33
|
|
|
return new DatabaseMigrationRepository( |
|
34
|
|
|
$c->get(Capsule::class)->getDatabaseManager(), |
|
35
|
|
|
$c->get('migration-table') |
|
36
|
|
|
); |
|
37
|
|
|
}); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function setMigrator(Container $c) |
|
41
|
|
|
{ |
|
42
|
|
|
$c->set(Migrator::class, function (Container $c) { |
|
43
|
|
|
return new \Schnittstabil\Dartisan\Migrator( |
|
44
|
|
|
$c->get(DatabaseMigrationRepository::class), |
|
45
|
|
|
$c->get(Capsule::class)->getDatabaseManager(), |
|
46
|
|
|
$c->get(Filesystem::class), |
|
47
|
|
|
$c->get(OutputInterface::class) |
|
48
|
|
|
); |
|
49
|
|
|
}); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function setMigrationCreator(Container $c) |
|
53
|
|
|
{ |
|
54
|
|
|
$c->set(MigrationCreator::class, function (Container $c) { |
|
55
|
|
|
return new MigrationCreator($c->get(Filesystem::class)); |
|
56
|
|
|
}); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function __invoke(Container $c) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->setCapsule($c); |
|
62
|
|
|
$this->setDatabaseMigrationRepository($c); |
|
63
|
|
|
$this->setMigrator($c); |
|
64
|
|
|
$this->setMigrationCreator($c); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|