CookieConsentServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
c 0
b 0
f 0
rs 9.536
cc 2
nc 2
nop 0
1
<?php
2
3
namespace DigiFactory\CookieConsent;
4
5
use DigiFactory\CookieConsent\Contracts\ConsentProvider;
6
use Illuminate\Foundation\Application;
7
use Illuminate\Support\Facades\Blade;
8
use Illuminate\Support\ServiceProvider;
9
10
class CookieConsentServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Bootstrap the application services.
14
     */
15
    public function boot()
16
    {
17
        Blade::if('cookieConsentNecessary', function () {
18
            return app('cookie-consent')->forNecessary();
19
        });
20
21
        Blade::if('cookieConsentPreferences', function () {
22
            return app('cookie-consent')->forPreferences();
23
        });
24
25
        Blade::if('cookieConsentStatistics', function () {
26
            return app('cookie-consent')->forStatistics();
27
        });
28
29
        Blade::if('cookieConsentMarketing', function () {
30
            return app('cookie-consent')->forMarketing();
31
        });
32
33
        if ($this->app->runningInConsole()) {
34
            $this->publishes([
35
                __DIR__.'/../config/config.php' => config_path('cookie-consent.php'),
36
            ], 'config');
37
        }
38
    }
39
40
    /**
41
     * Register the application services.
42
     */
43
    public function register()
44
    {
45
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'cookie-consent');
46
47
        if ($this->app instanceof Application) {
48
            $config = $this->app->config['cookie-consent'];
49
50
            $this->app->singleton(ConsentProvider::class, $config['provider']);
51
            $this->app->bind('cookie-consent', CookieConsent::class);
52
        }
53
    }
54
}
55