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: 14: 15: 16:
17: protected $defer = false;
18:
19: 20: 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: 35: 36: 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:
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:
65: if (isset($config['schema'])) {
66: $sessionVars['CURRENT_SCHEMA'] = $config['schema'];
67: }
68:
69: $db->setSessionVars($sessionVars);
70:
71: return $db;
72: });
73: }
74:
75: 76: 77: 78: 79:
80: public function provides()
81: {
82: return [];
83: }
84: }
85: