DatabaseServiceProvider::provides()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 2
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 0
cts 1
cp 0
crap 2
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