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