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
|
|
|
|