DatabaseServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 7
c 2
b 0
f 1
dl 0
loc 40
rs 10
ccs 0
cts 12
cp 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 3 1
A provides() 0 3 1
A registerConnectionServices() 0 14 1
1
<?php
2
3
namespace Nip\Database;
4
5
use Nip\Application\ApplicationInterface;
6
use Nip\Container\ServiceProviders\Providers\AbstractServiceProvider;
7
use Nip\Database\Connections\ConnectionFactory;
8
9
/**
10
 * Class Manager
11
 * @package Nip\Database
12
 */
13
class DatabaseServiceProvider extends AbstractServiceProvider
14
{
15
    /**
16
     * Register the service provider.
17
     *
18
     * @return void
19
     */
20
    public function register()
21
    {
22
        $this->registerConnectionServices();
23
    }
24
25
    /**
26
     * Register the primary database bindings.
27
     *
28
     * @return void
29
     */
30
    protected function registerConnectionServices()
31
    {
32
        // The connection factory is used to create the actual connection instances on
33
        // the database. We will inject the factory into the manager so that it may
34
        // make the connections while they are actually needed and not of before.
35
        $this->getContainer()->share('db.factory', ConnectionFactory::class);
36
37
        // The database manager is used to resolve various connections, since multiple
38
        // connections might be managed. It also implements the connection resolver
39
        // interface which may be used by other components requiring connections.
40
        $this->getContainer()->share('db', DatabaseManager::class);
41
42
        $this->getContainer()->share('db.connection', function () {
43
            return app('db')->connection();
44
        });
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function provides()
51
    {
52
        return ['db', 'db.factory', 'db.connection'];
53
    }
54
}
55