Completed
Pull Request — master (#575)
by Gerardo
02:50
created

AdminLteServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Test Coverage

Coverage 11.11%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 7
dl 0
loc 79
ccs 5
cts 45
cp 0.1111
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 10 1
A boot() 0 17 1
A loadViews() 0 7 1
A loadTranslations() 0 6 1
A loadConfig() 0 6 1
A packagePath() 0 4 1
A registerCommands() 0 7 1
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\Container\Container;
7
use Illuminate\Contracts\Events\Dispatcher;
8
use Illuminate\Contracts\View\Factory;
9
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
10
use JeroenNoten\LaravelAdminLte\Console\AdminLteInstallCommand;
11
use JeroenNoten\LaravelAdminLte\Console\AdminLtePluginCommand;
12
use JeroenNoten\LaravelAdminLte\Console\AdminLteStatusCommand;
13
use JeroenNoten\LaravelAdminLte\Console\AdminLteUpdateCommand;
14
use JeroenNoten\LaravelAdminLte\Events\BuildingMenu;
15
use JeroenNoten\LaravelAdminLte\Http\ViewComposers\AdminLteComposer;
16
17
class AdminLteServiceProvider extends BaseServiceProvider
18
{
19
    public function register()
20
    {
21
        $this->app->singleton(AdminLte::class, function (Container $app) {
22
            return new AdminLte(
23
                $app['config']['adminlte.filters'],
24
                $app['events'],
25
                $app
26
            );
27
        });
28
    }
29
30
    public function boot(
31
        Factory $view,
32
        Dispatcher $events,
33
        Repository $config
34
    ) {
35
        $this->loadViews();
36
37
        $this->loadTranslations();
38
39
        $this->loadConfig();
40
41
        $this->registerCommands();
42
43
        $this->registerViewComposers($view);
44
45
        static::registerMenu($events, $config);
46
    }
47
48
    private function loadViews()
49
    {
50
        $viewsPathUser = resource_path('views/vendor/jeroennoten/laravel-adminlte');
51
        $this->loadViewsFrom($viewsPathUser, 'adminlte');
52
        $viewsPath = $this->packagePath('resources/views');
53
        $this->loadViewsFrom($viewsPath, 'adminlte');
54
    }
55
56
    private function loadTranslations()
57
    {
58
        $translationsPath = $this->packagePath('resources/lang');
59
60
        $this->loadTranslationsFrom($translationsPath, 'adminlte');
61
    }
62
63
    private function loadConfig()
64
    {
65
        $configPath = $this->packagePath('config/adminlte.php');
66
67
        $this->mergeConfigFrom($configPath, 'adminlte');
68
    }
69
70
    private function packagePath($path)
71
    {
72
        return __DIR__."/../$path";
73
    }
74
75
    private function registerCommands()
76
    {
77
        $this->commands(AdminLteInstallCommand::class);
78
        $this->commands(AdminLteStatusCommand::class);
79
        $this->commands(AdminLteUpdateCommand::class);
80
        $this->commands(AdminLtePluginCommand::class);
81
    }
82
83
    private function registerViewComposers(Factory $view)
84
    {
85
        $view->composer('adminlte::page', AdminLteComposer::class);
86
    }
87
88 1
    public static function registerMenu(Dispatcher $events, Repository $config)
89
    {
90
        $events->listen(BuildingMenu::class, function (BuildingMenu $event) use ($config) {
91 1
            $menu = $config->get('adminlte.menu');
92 1
            call_user_func_array([$event->menu, 'add'], $menu);
93 1
        });
94 1
    }
95
}
96