Completed
Push — master ( a4ca65...20e185 )
by Jeroen
05:02
created

ServiceProvider   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 4.88%

Importance

Changes 9
Bugs 1 Features 4
Metric Value
wmc 11
c 9
b 1
f 4
lcom 1
cbo 5
dl 0
loc 93
ccs 2
cts 41
cp 0.0488
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A boot() 0 19 1
A loadViews() 0 10 1
A loadTranslations() 0 10 1
A publishConfig() 0 10 1
A publishAssets() 0 6 1
A packagePath() 0 4 1
A registerCommands() 0 7 2
A registerViewComposers() 0 4 1
A registerMenu() 0 7 1
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte;
4
5
use Illuminate\Contracts\Config\Repository;
6
use Illuminate\Contracts\Events\Dispatcher;
7
use Illuminate\Contracts\View\Factory;
8
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
9
use JeroenNoten\LaravelAdminLte\Console\MakeAdminLteCommand;
10
use JeroenNoten\LaravelAdminLte\Events\BuildingMenu;
11
use JeroenNoten\LaravelAdminLte\Http\ViewComposers\AdminLteComposer;
12
13
class ServiceProvider extends BaseServiceProvider
14
{
15
    public function register()
16
    {
17
        //
18
    }
19
20
    public function boot(
21
        Factory $view,
22
        Dispatcher $events,
23
        Repository $config
24
    ) {
25
        $this->loadViews();
26
27
        $this->loadTranslations();
28
29
        $this->publishConfig();
30
31
        $this->publishAssets();
32
33
        $this->registerCommands();
34
35
        $this->registerViewComposers($view);
36
37
        static::registerMenu($events, $config);
38
    }
39
40 1
    private function loadViews()
41
    {
42
        $viewsPath = $this->packagePath('resources/views');
43
44
        $this->loadViewsFrom($viewsPath, 'adminlte');
45
46
        $this->publishes([
47
            $viewsPath => base_path('resources/views/vendor/adminlte'),
48
        ], 'views');
49 1
    }
50
51
    private function loadTranslations()
52
    {
53
        $translationsPath = $this->packagePath('resources/lang');
54
55
        $this->loadTranslationsFrom($translationsPath, 'adminlte');
56
57
        $this->publishes([
58
            $translationsPath => base_path('resources/lang/vendor/adminlte'),
59
        ], 'translations');
60
    }
61
62
    private function publishConfig()
63
    {
64
        $configPath = $this->packagePath('config/adminlte.php');
65
66
        $this->publishes([
67
            $configPath => config_path('adminlte.php'),
68
        ], 'config');
69
70
        $this->mergeConfigFrom($configPath, 'adminlte');
71
    }
72
73
    private function publishAssets()
74
    {
75
        $this->publishes([
76
            $this->packagePath('resources/assets') => public_path('vendor/adminlte'),
77
        ], 'assets');
78
    }
79
80
    private function packagePath($path)
81
    {
82
        return __DIR__."/../$path";
83
    }
84
85
    private function registerCommands()
86
    {
87
        // Laravel >=5.2 only
88
        if (class_exists('Illuminate\\Auth\\Console\\MakeAuthCommand')) {
89
            $this->commands(MakeAdminLteCommand::class);
90
        }
91
    }
92
93
    private function registerViewComposers(Factory $view)
94
    {
95
        $view->composer('adminlte::page', AdminLteComposer::class);
96
    }
97
98
    public static function registerMenu(Dispatcher $events, Repository $config)
99
    {
100
        $events->listen(BuildingMenu::class, function (BuildingMenu $event) use ($config) {
101
            $menu = $config->get('adminlte.menu');
102
            call_user_func_array([$event->menu, 'add'], $menu);
103
        });
104
    }
105
}
106