Completed
Push — master ( 9cef8b...978d67 )
by Jeroen
03:13
created

ServiceProvider   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 4.26%

Importance

Changes 8
Bugs 1 Features 4
Metric Value
wmc 11
c 8
b 1
f 4
lcom 1
cbo 5
dl 0
loc 112
ccs 2
cts 47
cp 0.0426
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A boot() 0 19 1
A loadViews() 0 13 1
A loadTranslations() 0 15 1
A publishConfig() 0 13 1
A publishAssets() 0 11 1
A packagePath() 0 4 1
A registerCommands() 0 7 2
A registerViewComposers() 0 4 1
A registerMenu() 0 10 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
            [
48
                $viewsPath => base_path('resources/views/vendor/adminlte'),
49 1
            ],
50
            'views'
51
        );
52
    }
53
54
    private function loadTranslations()
55
    {
56
        $translationsPath = $this->packagePath('resources/lang');
57
58
        $this->loadTranslationsFrom($translationsPath, 'adminlte');
59
60
        $this->publishes(
61
            [
62
                $translationsPath => base_path(
63
                    'resources/lang/vendor/adminlte'
64
                ),
65
            ],
66
            'translations'
67
        );
68
    }
69
70
    private function publishConfig()
71
    {
72
        $configPath = $this->packagePath('config/adminlte.php');
73
74
        $this->publishes(
75
            [
76
                $configPath => config_path('adminlte.php'),
77
            ],
78
            'config'
79
        );
80
81
        $this->mergeConfigFrom($configPath, 'adminlte');
82
    }
83
84
    private function publishAssets()
85
    {
86
        $this->publishes(
87
            [
88
                $this->packagePath('resources/assets') => public_path(
89
                    'vendor/adminlte'
90
                ),
91
            ],
92
            'assets'
93
        );
94
    }
95
96
    private function packagePath($path)
97
    {
98
        return __DIR__."/../$path";
99
    }
100
101
    private function registerCommands()
102
    {
103
        // Laravel >=5.2 only
104
        if (class_exists('Illuminate\\Auth\\Console\\MakeAuthCommand')) {
105
            $this->commands(MakeAdminLteCommand::class);
106
        }
107
    }
108
109
    private function registerViewComposers(Factory $view)
110
    {
111
        $view->composer('adminlte::page', AdminLteComposer::class);
112
    }
113
114
    public static function registerMenu(Dispatcher $events, Repository $config)
115
    {
116
        $events->listen(
117
            BuildingMenu::class,
118
            function (BuildingMenu $event) use ($config) {
119
                $menu = $config->get('adminlte.menu');
120
                call_user_func_array([$event->menu, 'add'], $menu);
121
            }
122
        );
123
    }
124
}
125