Completed
Push — master ( e15c58...b150a8 )
by Changwan
07:08
created

EloquentServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 2
rs 9.4285
c 1
b 0
f 0
1
<?php
2
namespace Wandu\Bridges\Eloquent;
3
4
use Illuminate\Database\Capsule\Manager;
5
use Wandu\Bridges\Eloquent\Migrator\MigrateAdapter;
6
use Wandu\Bridges\Eloquent\Migrator\MigrateTemplate;
7
use Wandu\Database\Migrator\MigrateAdapterInterface;
8
use Wandu\Database\Migrator\MigrateTemplateInterface;
9
use Wandu\DI\ContainerInterface;
10
use Wandu\DI\ServiceProviderInterface;
11
use function Wandu\Foundation\config;
12
13
class EloquentServiceProvider implements ServiceProviderInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function register(ContainerInterface $app)
19
    {
20
        $app->closure(Manager::class, function () {
21
            $capsule = new Manager;
22
            foreach (config('database.connections', []) as $name => $connection) {
23
                $capsule->addConnection($connection, $name);
24
            }
25
            return $capsule;
26
        });
27
        $app->alias('database', Manager::class);
28
        
29
        $app->bind(MigrateTemplateInterface::class, MigrateTemplate::class);
30
        $app->bind(MigrateAdapterInterface::class, MigrateAdapter::class);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function boot(ContainerInterface $app)
37
    {
38
        $app->get(Manager::class)->setAsGlobal();
39
        $app->get(Manager::class)->bootEloquent();
40
    }
41
}
42