EloquentServiceProvider::boot()   A
last analyzed

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 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 2
rs 9.4285
1
<?php
2
namespace Wandu\Service\Eloquent;
3
4
use Illuminate\Database\Capsule\Manager;
5
use Wandu\Config\Contracts\Config;
6
use Wandu\Migrator\Contracts\Adapter;
7
use Wandu\Migrator\Contracts\MigrationTemplate;
8
use Wandu\DI\ContainerInterface;
9
use Wandu\DI\ServiceProviderInterface;
10
11
class EloquentServiceProvider implements ServiceProviderInterface 
12
{
13
    public function register(ContainerInterface $app)
14
    {
15
        $app->bind(Manager::class)->after(function (Manager $manager, Config $config) {
16
            foreach ($config->get('database.connections', []) as $name => $connection) {
17
                $manager->addConnection($connection, $name);
18
            }
19
            return $manager;
20
        });
21
        $app->bind(Adapter::class, EloquentAdapter::class);
22
        $app->bind(MigrationTemplate::class, EloquentTemplate::class);
23
    }
24
25
    public function boot(ContainerInterface $app)
26
    {
27
        $app->get(Manager::class)->setAsGlobal();
28
        $app->get(Manager::class)->bootEloquent();
29
    }
30
}
31