Completed
Push — master ( 603a9f...7527cc )
by Changwan
05:44
created

EloquentServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 20
ccs 0
cts 16
cp 0
rs 10
wmc 3
lcom 0
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 11 2
A boot() 0 5 1
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