setCustomResolverForPgsql()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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