Skip to content

Commit 10bade7

Browse files
committed
Service with dB object
1 parent afccb7f commit 10bade7

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/SqlSrvServiceProvider.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace Julfiker\SqlSrv;
33

4+
use App\Connection\SqlServerConnection;
5+
use Illuminate\Database\Connection;
46
use Illuminate\Support\ServiceProvider;
57

68
/**
@@ -12,21 +14,47 @@
1214
*/
1315
class SqlSrvServiceProvider extends ServiceProvider
1416
{
17+
1518
/**
16-
* Bootstrap the application services.
19+
* Indicates if loading of the provider is deferred.
1720
*
18-
* @return void
21+
* @var bool
22+
*/
23+
protected $defer = false;
24+
25+
/**
26+
* Boot Oci8 Provider.
1927
*/
2028
public function boot()
2129
{
2230
}
2331

2432
/**
25-
* Register the application services.
33+
* Register the service provider.
2634
*
2735
* @return void
2836
*/
2937
public function register()
3038
{
39+
40+
Connection::resolverFor('sqlsrv', function ($connection, $database, $prefix, $config) {
41+
$db = new SqlServerConnection($connection, $database, $prefix, $config);
42+
43+
if (! empty($config['skip_session_vars'])) {
44+
return $db;
45+
}
46+
47+
return $db;
48+
});
49+
}
50+
51+
/**
52+
* Get the services provided by the provider.
53+
*
54+
* @return string[]
55+
*/
56+
public function provides()
57+
{
58+
return [];
3159
}
3260
}

0 commit comments

Comments
 (0)