1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omatech\Enigma; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Connection; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use Omatech\Enigma\Commands\ReIndexCommand; |
8
|
|
|
use Omatech\Enigma\Database\Contracts\DBInterface; |
9
|
|
|
use Omatech\Enigma\Database\Eloquent\DB; |
10
|
|
|
use Omatech\Enigma\Database\MySqlConnection; |
11
|
|
|
use Omatech\Enigma\Database\PostgresConnection; |
12
|
|
|
use Omatech\Enigma\Database\SQLiteConnection; |
13
|
|
|
use Omatech\Enigma\Database\SqlServerConnection; |
14
|
|
|
|
15
|
|
|
class EnigmaServiceProvider extends ServiceProvider |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Bootstrap the application services. |
19
|
|
|
*/ |
20
|
51 |
|
public function boot() |
21
|
|
|
{ |
22
|
51 |
|
if ($this->app->runningInConsole()) { |
23
|
51 |
|
$this->publishes([ |
24
|
51 |
|
__DIR__.'/../config/config.php' => config_path('enigma.php'), |
25
|
51 |
|
], 'config'); |
26
|
|
|
} |
27
|
51 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Register the application services. |
31
|
|
|
*/ |
32
|
51 |
|
public function register(): void |
33
|
|
|
{ |
34
|
51 |
|
app()->singleton(DBInterface::class, DB::class); |
35
|
|
|
|
36
|
|
|
Connection::resolverFor('mysql', static function ($connection, $database, $prefix, $config) { |
37
|
15 |
|
return new MySqlConnection($connection, $database, $prefix, $config); |
38
|
51 |
|
}); |
39
|
|
|
|
40
|
|
|
Connection::resolverFor('pgsql', static function ($connection, $database, $prefix, $config) { |
41
|
12 |
|
return new PostgresConnection($connection, $database, $prefix, $config); |
42
|
51 |
|
}); |
43
|
|
|
|
44
|
|
|
Connection::resolverFor('sqlite', static function ($connection, $database, $prefix, $config) { |
45
|
12 |
|
return new SQLiteConnection($connection, $database, $prefix, $config); |
46
|
51 |
|
}); |
47
|
|
|
|
48
|
|
|
Connection::resolverFor('sqlsrv', static function ($connection, $database, $prefix, $config) { |
49
|
12 |
|
return new SqlServerConnection($connection, $database, $prefix, $config); |
50
|
51 |
|
}); |
51
|
|
|
|
52
|
51 |
|
$this->commands(ReIndexCommand::class); |
53
|
|
|
|
54
|
51 |
|
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'enigma'); |
55
|
51 |
|
} |
56
|
|
|
} |
57
|
|
|
|