Completed
Push — dev ( 0c367d...471bb6 )
by Amr
02:10
created

SettingsServiceProvider::boot()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 2.0009

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 15
cts 16
cp 0.9375
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 15
nc 2
nop 0
crap 2.0009
1
<?php
2
3
namespace Merodiro\Settings;
4
5
use Illuminate\Support\ServiceProvider;
6
use Illuminate\Support\Facades\Blade;
7
8
use Merodiro\Settings\Commands\SettingsCache;
9
use Merodiro\Settings\Commands\SettingsClear;
10
use Merodiro\Settings\Observers\SettingObserver;
11
use Merodiro\Settings\Models\Setting;
12
13
class SettingsServiceProvider extends ServiceProvider
14
{
15 44
    public function boot()
16
    {
17 44
        $this->publishes([
18 44
            __DIR__.'/config/settings.php' => config_path('settings.php'),
19 44
        ], 'config');
20
21 44
        $this->mergeConfigFrom(
22 44
            __DIR__.'/config/settings.php',
23 44
            'settings'
24
        );
25
26 44
        $this->loadMigrationsFrom(__DIR__ . '/migrations');
27
28 44
        if ($this->app->runningInConsole()) {
29 44
            $this->commands([
30 44
                SettingsCache::class,
31
                SettingsClear::class
32
            ]);
33
        }
34 44
        Setting::observe(SettingObserver::class);
35
36 44
        Blade::directive('settings', function ($expression) {
37
            return "<?php echo Settings::get($expression); ?>";
38 44
        });
39 44
    }
40
41
    /**
42
     * Register any package services.
43
     *
44
     * @return void
45
     */
46
    public function register()
47
    {
48 44
        $this->app->singleton(SettingsManger::class, function () {
49 26
            return new SettingsManger();
50 44
        });
51 44
    }
52
}
53