Completed
Push — master ( 1db263...be4043 )
by Michael
02:39
created

DatabaseServiceProvider::setMigrationCreator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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