Completed
Push — master ( ac5b6c...2ebd86 )
by recca
02:43
created

ConfigServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Recca0120\Config;
4
5
use Illuminate\Contracts\Http\Kernel;
6
use Illuminate\Support\ServiceProvider;
7
use Recca0120\Config\Contracts\Repository;
8
use Recca0120\Config\Middleware\SwapConfigRepository;
9
use Recca0120\Config\Repositories\DatabaseRepository;
10
11
class ConfigServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap any application services.
15
     *
16
     * @param \Illuminate\Contracts\Http\Kernel $kernel
17
     */
18 1
    public function boot(Kernel $kernel)
19
    {
20 1
        $kernel->pushMiddleware(SwapConfigRepository::class);
21
22 1
        if ($this->app->runningInConsole() === true) {
23 1
            $this->handlePublishes();
24 1
        }
25 1
    }
26
27
    /**
28
     * Register any application services.
29
     */
30
    public function register()
31
    {
32 1
        $this->app->singleton(Repository::class, function ($app) {
33
            $config = [
34
                'protected' => [
35 1
                    'app',
36 1
                    'auth.defaults.guard',
37 1
                ],
38 1
                'path' => $app->storagePath().'/app/',
39 1
            ];
40
41 1
            return new DatabaseRepository($app['config'], $app->make(Config::class), $app['files'], $config);
42 1
        });
43 1
    }
44
45
    /**
46
     * Get the services provided by the provider.
47
     *
48
     * @return array
49
     */
50 1
    public function provides()
51
    {
52 1
        return ['config'];
53
    }
54
55
    /**
56
     * handle publishes.
57
     */
58 2
    protected function handlePublishes()
59
    {
60 1
        $this->publishes([
61 1
            __DIR__.'/../database/migrations/' => $this->app->databasePath().'/migrations',
62 1
        ], 'migrations');
63 2
    }
64
}
65