ServiceProvider::boot()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
namespace HughCube\HttpSecurity;
4
5
use Illuminate\Foundation\Application as LaravelApplication;
6
use Illuminate\Foundation\Http\Kernel;
7
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
8
use Laravel\Lumen\Application as LumenApplication;
9
10
class ServiceProvider extends BaseServiceProvider
11
{
12
    /**
13
     * Boot the service provider.
14
     *
15
     * @return void
16
     */
17
    public function boot()
18
    {
19
        if ($this->app instanceof LaravelApplication && !$this->app->runningInConsole()) {
20
            /** @var Kernel $kernel */
21
            $kernel = $this->app->make(Kernel::class);
22
            $kernel->prependMiddleware(Middleware::class);
23
        } elseif ($this->app instanceof LumenApplication) {
24
            $this->app->middleware([Middleware::class]);
25
        }
26
    }
27
28
    /**
29
     * Register the service provider.
30
     *
31
     * @return void
32
     */
33
    public function register()
34
    {
35
        $source = realpath($raw = __DIR__.'/../config/httpSecurity.php') ?: $raw;
36
37
        if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
38
            $this->publishes([$source => config_path('httpSecurity.php')]);
39
        } elseif ($this->app instanceof LumenApplication) {
40
            $this->app->configure('httpSecurity');
41
        }
42
43
        if ($this->app instanceof LaravelApplication && !$this->app->configurationIsCached()) {
44
            $this->mergeConfigFrom($source, 'httpSecurity');
45
        }
46
    }
47
}
48