ApiDriverServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TomHart\Database;
4
5
use Illuminate\Database\Connection;
6
use Illuminate\Support\ServiceProvider;
7
use TomHart\Database\Database\ApiConnection;
8
9
class ApiDriverServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Register any application services.
13
     *
14
     * @return void
15
     */
16
    public function register(): void
17
    {
18
        Connection::resolverFor('api', static function ($connection, $database, $prefix, $config) {
19
            if (app()->has(ApiConnection::class)) {
20
                return app(ApiConnection::class);
21
            }
22
23
            return new ApiConnection($connection, $database, $prefix, $config);
24
        });
25
26
        $this->mergeConfigFrom(__DIR__ . '/../config/api-database.php', 'api-database');
27
    }
28
29
    /**
30
     * Boot the service.
31
     */
32
    public function boot(): void
33
    {
34
        $this->publishes([
35
            __DIR__ . '/../config/api-database.php' => config_path('api-database.php'),
36
        ], 'config');
37
    }
38
}
39