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

EloquentServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 29
ccs 0
cts 18
cp 0
rs 10
c 1
b 0
f 0
wmc 3
lcom 0
cbo 2

2 Methods

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