Completed
Pull Request — master (#603)
by Florian
03:29
created

AdminLteServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Test Coverage

Coverage 11.9%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 7
dl 0
loc 77
ccs 5
cts 42
cp 0.119
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 17 1
A loadViews() 0 5 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
A register() 0 10 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
        $viewsPath = $this->packagePath('resources/views');
51
        $this->loadViewsFrom($viewsPath, 'adminlte');
52
    }
53
54
    private function loadTranslations()
55
    {
56
        $translationsPath = $this->packagePath('resources/lang');
57
58
        $this->loadTranslationsFrom($translationsPath, 'adminlte');
59
    }
60
61
    private function loadConfig()
62
    {
63
        $configPath = $this->packagePath('config/adminlte.php');
64
65
        $this->mergeConfigFrom($configPath, 'adminlte');
66
    }
67
68
    private function packagePath($path)
69
    {
70
        return __DIR__."/../$path";
71
    }
72
73
    private function registerCommands()
74
    {
75
        $this->commands(AdminLteInstallCommand::class);
76
        $this->commands(AdminLteStatusCommand::class);
77
        $this->commands(AdminLteUpdateCommand::class);
78
        $this->commands(AdminLtePluginCommand::class);
79
    }
80
81
    private function registerViewComposers(Factory $view)
82
    {
83
        $view->composer('adminlte::page', AdminLteComposer::class);
84
    }
85
86 1
    public static function registerMenu(Dispatcher $events, Repository $config)
87
    {
88
        $events->listen(BuildingMenu::class, function (BuildingMenu $event) use ($config) {
89 1
            $menu = $config->get('adminlte.menu');
90 1
            call_user_func_array([$event->menu, 'add'], $menu);
91 1
        });
92 1
    }
93
}
94