registerConnectionServices()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 16
ccs 0
cts 6
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Ianrizky\Illuminate\Database;
4
5
use Ianrizky\Illuminate\Database\Connectors\ConnectionFactory as CustomConnectionFactory;
6
use Illuminate\Database\DatabaseManager;
7
use Illuminate\Database\DatabaseServiceProvider as BaseDatabaseServiceProvider;
8
9
class DatabaseServiceProvider extends BaseDatabaseServiceProvider
10
{
11
    /**
12
     * {@inheritDoc}
13
     */
14
    public function register()
15
    {
16
        parent::register();
17
18
        $this->mergeConfigFrom(
19
            __DIR__ . '/../../../config/database.php', 'database'
20
        );
21
    }
22
23
    /**
24
     * {@inheritDoc}
25
     */
26
    protected function registerConnectionServices()
27
    {
28
        /**
29
         * The db.factory container instance has been changed
30
         * to implement custom query builder.
31
         */
32
        $this->app->singleton('db.factory', function ($app) {
33
            return new CustomConnectionFactory($app);
34
        });
35
36
        $this->app->singleton('db', function ($app) {
37
            return new DatabaseManager($app, $app['db.factory']);
38
        });
39
40
        $this->app->bind('db.connection', function ($app) {
41
            return $app['db']->connection();
42
        });
43
    }
44
}
45