Oci8ServiceProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 79
ccs 0
cts 40
cp 0
rs 10
wmc 7
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 10 1
B register() 0 40 5
A provides() 0 4 1
1
<?php
2
3
namespace Yajra\Oci8;
4
5
use Illuminate\Support\ServiceProvider;
6
use Yajra\Oci8\Auth\OracleUserProvider;
7
use Yajra\Oci8\Connectors\OracleConnector as Connector;
8
use Illuminate\Support\Facades\Auth;
9
10
class Oci8ServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Indicates if loading of the provider is deferred.
14
     *
15
     * @var bool
16
     */
17
    protected $defer = false;
18
19
    /**
20
     * Boot Oci8 Provider
21
     */
22
    public function boot()
23
    {
24
        $this->publishes([
25
            __DIR__ . '/../config/oracle.php' => config_path('oracle.php'),
26
        ], 'oracle');
27
28
        Auth::provider('oracle', function ($app, array $config) {
29
            return new OracleUserProvider($app['hash'], $config['model']);
30
        });
31
    }
32
33
    /**
34
     * Register the service provider.
35
     *
36
     * @return void
37
     */
38
    public function register()
39
    {
40
        if (file_exists(config_path('oracle.php'))) {
41
            $this->mergeConfigFrom(config_path('oracle.php'), 'database.connections');
42
        } else {
43
            $this->mergeConfigFrom(__DIR__ . '/../config/oracle.php', 'database.connections');
44
        }
45
46
        $this->app['db']->extend('oracle', function ($config) {
47
            $connector  = new Connector();
48
            $connection = $connector->connect($config);
49
            $db         = new Oci8Connection($connection, $config["database"], $config["prefix"], $config);
50
51
            if (! empty($config['skip_session_vars'])) {
52
                return $db;
53
            }
54
55
            // set oracle session variables
56
            $sessionVars = [
57
                'NLS_TIME_FORMAT'         => 'HH24:MI:SS',
58
                'NLS_DATE_FORMAT'         => 'YYYY-MM-DD HH24:MI:SS',
59
                'NLS_TIMESTAMP_FORMAT'    => 'YYYY-MM-DD HH24:MI:SS',
60
                'NLS_TIMESTAMP_TZ_FORMAT' => 'YYYY-MM-DD HH24:MI:SS TZH:TZM',
61
                'NLS_NUMERIC_CHARACTERS'  => '.,',
62
            ];
63
64
            // Like Postgres, Oracle allows the concept of "schema"
65
            if (isset($config['schema'])) {
66
                $sessionVars['CURRENT_SCHEMA'] = $config['schema'];
67
            }
68
            
69
            if (isset($config['session'])) {
70
                $sessionVars = array_merge($sessionVars, $config['session']);
71
            }
72
73
            $db->setSessionVars($sessionVars);
74
75
            return $db;
76
        });
77
    }
78
79
    /**
80
     * Get the services provided by the provider.
81
     *
82
     * @return string[]
83
     */
84
    public function provides()
85
    {
86
        return [];
87
    }
88
}
89