Passed
Push — master ( 2a5f36...212476 )
by Patrick
01:25
created

LaravelNomadServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php
2
namespace ShiftOneLabs\LaravelNomad;
3
4
use Illuminate\Database\Connection;
5
use Illuminate\Support\ServiceProvider;
6
use ShiftOneLabs\LaravelNomad\Extension\Database\MySqlConnection;
7
use ShiftOneLabs\LaravelNomad\Extension\Database\SQLiteConnection;
8
use ShiftOneLabs\LaravelNomad\Extension\Database\PostgresConnection;
9
use ShiftOneLabs\LaravelNomad\Extension\Database\SqlServerConnection;
10
11
class LaravelNomadServiceProvider extends ServiceProvider
12
{
13
14
    /**
15
     * Bootstrap any application services.
16
     *
17
     * @return void
18
     */
19
    public function boot()
20
    {
21
        //
22
    }
23
24
    /**
25
     * Register any application services.
26
     *
27
     * @return void
28
     */
29 37
    public function register()
30
    {
31 37
        if (method_exists(Connection::class, 'resolverFor')) {
32
            // Laravel 5.4 and newer
33
            Connection::resolverFor('mysql', function ($connection, $database, $prefix, $config) {
34 7
                return new MySqlConnection($connection, $database, $prefix, $config);
35 37
            });
36
            Connection::resolverFor('pgsql', function ($connection, $database, $prefix, $config) {
37 7
                return new PostgresConnection($connection, $database, $prefix, $config);
38 37
            });
39
            Connection::resolverFor('sqlite', function ($connection, $database, $prefix, $config) {
40 7
                return new SQLiteConnection($connection, $database, $prefix, $config);
41 37
            });
42 37
            Connection::resolverFor('sqlsrv', function ($connection, $database, $prefix, $config) {
43 7
                return new SqlServerConnection($connection, $database, $prefix, $config);
44 37
            });
45 37
        } else {
46
            // Laravel 5.3 and older
47
            $this->app->bind('db.connection.mysql', 'ShiftOneLabs\LaravelNomad\Extension\Database\MySqlConnection');
48
            $this->app->bind('db.connection.pgsql', 'ShiftOneLabs\LaravelNomad\Extension\Database\PostgresConnection');
49
            $this->app->bind('db.connection.sqlite', 'ShiftOneLabs\LaravelNomad\Extension\Database\SQLiteConnection');
50
            $this->app->bind('db.connection.sqlsrv', 'ShiftOneLabs\LaravelNomad\Extension\Database\SqlServerConnection');
51
        }
52 37
    }
53
}
54