Passed
Pull Request — master (#721)
by Florian
09:26
created

AdminLteServiceProvider   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 169
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 59
c 0
b 0
f 0
dl 0
loc 169
rs 10
ccs 43
cts 43
cp 1
wmc 11

10 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 10 1
A registerMenu() 0 11 2
A registerCommands() 0 7 1
A registerViewComposers() 0 3 1
A boot() 0 9 1
A packagePath() 0 3 1
A loadTranslations() 0 4 1
A loadConfig() 0 4 1
A loadViews() 0 4 1
A loadComponents() 0 38 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
    /**
20
     * Register the package services.
21
     *
22
     * @return void
23
     */
24 29
    public function register()
25
    {
26
        // Bind a singleton instance of the AdminLte class into the service
27
        // container.
28
29
        $this->app->singleton(AdminLte::class, function (Container $app) {
30 3
            return new AdminLte(
31 3
                $app['config']['adminlte.filters'],
32 3
                $app['events'],
33
                $app
34
            );
35 29
        });
36 29
    }
37
38
    /**
39
     * Bootstrap the package's services.
40
     *
41
     * @return void
42
     */
43 29
    public function boot(Factory $view, Dispatcher $events, Repository $config)
44
    {
45 29
        $this->loadViews();
46 29
        $this->loadTranslations();
47 29
        $this->loadConfig();
48 29
        $this->registerCommands();
49 29
        $this->registerViewComposers($view);
50 29
        $this->registerMenu($events, $config);
51 29
        $this->loadComponents();
52
    }
53
54
    /**
55
     * Load the package views.
56
     *
57
     * @return void
58 29
     */
59
    private function loadViews()
60 29
    {
61 29
        $viewsPath = $this->packagePath('resources/views');
62 29
        $this->loadViewsFrom($viewsPath, 'adminlte');
63
    }
64
65
    /**
66
     * Load the package translations.
67
     *
68
     * @return void
69 29
     */
70
    private function loadTranslations()
71 29
    {
72 29
        $translationsPath = $this->packagePath('resources/lang');
73 29
        $this->loadTranslationsFrom($translationsPath, 'adminlte');
74
    }
75
76
    /**
77
     * Load the package config.
78
     *
79
     * @return void
80 29
     */
81
    private function loadConfig()
82 29
    {
83 29
        $configPath = $this->packagePath('config/adminlte.php');
84 29
        $this->mergeConfigFrom($configPath, 'adminlte');
85
    }
86
87
    /**
88
     * Get the absolute path to some package resource.
89
     *
90
     * @param string $path The relative path to the resource
91
     * @return string
92 29
     */
93
    private function packagePath($path)
94 29
    {
95
        return __DIR__."/../$path";
96
    }
97
98
    /**
99
     * Register the package's artisan commands.
100
     *
101
     * @return void
102 29
     */
103
    private function registerCommands()
104 29
    {
105 29
        $this->commands([
106
            AdminLteInstallCommand::class,
107
            AdminLteStatusCommand::class,
108
            AdminLteUpdateCommand::class,
109
            AdminLtePluginCommand::class,
110 29
        ]);
111
    }
112
113
    /**
114
     * Register the package's view composers.
115
     *
116
     * @return void
117 29
     */
118
    private function registerViewComposers(Factory $view)
119 29
    {
120 29
        $view->composer('adminlte::page', AdminLteComposer::class);
121
    }
122
123
    /**
124
     * Register the menu events handlers.
125
     *
126
     * @return void
127 29
     */
128
    private static function registerMenu(Dispatcher $events, Repository $config)
129
    {
130
        // Register a handler for the BuildingMenu event, this handler will add
131
        // the menu defined on the config file to the menu builder instance.
132 29
133 29
        $events->listen(
134
            BuildingMenu::class,
135 1
            function (BuildingMenu $event) use ($config) {
136 1
                $menu = $config->get('adminlte.menu', []);
137 1
                $menu = is_array($menu) ? $menu : [];
138 29
                $event->menu->add(...$menu);
139
            }
140 29
        );
141
    }
142
    
143
    /**
144
     * Load the Components
145
     *
146
     * @return void
147
     */
148
    private function loadComponents()
149
    {
150
        /**
151
         * FORM COMPONENTS
152
         */
153
154
        Blade::component('adminlte-input', Components\Input::class);
0 ignored issues
show
Bug introduced by
The type JeroenNoten\LaravelAdminLte\Blade was not found. Did you mean Blade? If so, make sure to prefix the type with \.
Loading history...
155
        Blade::component('adminlte-input-file', Components\InputFile::class);
156
        Blade::component('adminlte-input-color', Components\InputColor::class);
157
        Blade::component('adminlte-input-date', Components\InputDate::class);
158
        Blade::component('adminlte-textarea', Components\Textarea::class);
159
        Blade::component('adminlte-select', Components\Select::class);
160
        Blade::component('adminlte-select2', Components\Select2::class);
161
        Blade::component('adminlte-select-icon', Components\SelectIcon::class);
162
        Blade::component('adminlte-option', Components\Option::class);
163
        Blade::component('adminlte-input-switch', Components\InputSwitch::class);
164
        Blade::component('adminlte-input-tag', Components\InputTag::class);
165
        Blade::component('adminlte-submit', Components\Submit::class);
166
        Blade::component('adminlte-text-editor', Components\TextEditor::class);
167
        Blade::component('adminlte-date-range', Components\DateRange::class);
168
        Blade::component('adminlte-input-slider', Components\InputSlider::class);
169
170
        /**
171
         * WIDGETS
172
         */
173
174
        Blade::component('adminlte-card', Components\Card::class);
175
        Blade::component('adminlte-info-box', Components\InfoBox::class);
176
        Blade::component('adminlte-small-box', Components\SmallBox::class);
177
        Blade::component('adminlte-profile-flat', Components\ProfileFlat::class);
178
        Blade::component('adminlte-profile-flat-item', Components\ProfileFlatItem::class);
179
        Blade::component('adminlte-profile-widget', Components\ProfileWidget::class);
180
        Blade::component('adminlte-profile-widget-item', Components\ProfileWidgetItem::class);
181
        Blade::component('adminlte-alert', Components\Alert::class);
182
        Blade::component('adminlte-callout', Components\Callout::class);
183
        Blade::component('adminlte-progress', Components\Progress::class);
184
        Blade::component('adminlte-modal', Components\Modal::class);
185
        Blade::component('adminlte-datatable', Components\Datatable::class);
186
    }
187
}
188