AdminLTETemplateServiceProvider   A
last analyzed

Complexity

Total Complexity 35

Size/Duplication

Total Lines 280
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 35
lcom 1
cbo 4
dl 0
loc 280
rs 9.6
c 0
b 0
f 0

25 Methods

Rating   Name   Duplication   Size   Complexity  
B register() 0 41 7
A registerGuestUserProvider() 0 4 1
A registerGravatarServiceProvider() 0 7 2
A defineRoutes() 0 10 2
A publishHomeController() 0 4 1
A changeRegisterController() 0 4 1
A changeLoginController() 0 4 1
A changeForgotPasswordController() 0 4 1
A publishNoGuestForgotPasswordController() 0 4 1
A changeResetPasswordController() 0 4 1
A publishPublicAssets() 0 4 1
A publishViews() 0 6 1
A publishResourceAssets() 0 4 1
A publishTests() 0 4 1
A publishLanguages() 0 6 1
A publishGravatar() 0 4 1
A publishConfig() 0 4 1
A publishWebRoutes() 0 4 1
A publishApiRoutes() 0 4 1
A publishAppServiceProvider() 0 4 1
A enableSpatieMenu() 0 6 2
A boot() 0 27 2
A publishDusk() 0 5 1
A publishDuskEnvironment() 0 4 1
A publishDatabaseConfig() 0 4 1
1
<?php
2
3
namespace Acacha\AdminLTETemplateLaravel\Providers;
4
5
use Acacha\AdminLTETemplateLaravel\Facades\AdminLTE;
6
use Acacha\User\Providers\GuestUserServiceProvider;
7
use Creativeorange\Gravatar\Facades\Gravatar;
8
use Creativeorange\Gravatar\GravatarServiceProvider;
9
use Illuminate\Console\DetectsApplicationNamespace;
10
use Illuminate\Support\ServiceProvider;
11
12
/**
13
 * Class AdminLTETemplateServiceProvider.
14
 */
15
class AdminLTETemplateServiceProvider extends ServiceProvider
16
{
17
    use DetectsApplicationNamespace;
18
19
    /**
20
     * Register the application services.
21
     */
22
    public function register()
23
    {
24
        if (!defined('ADMINLTETEMPLATE_PATH')) {
25
            define('ADMINLTETEMPLATE_PATH', realpath(__DIR__.'/../../'));
26
        }
27
28
        if ($this->app->runningInConsole()) {
29
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\PublishAdminLTE::class]);
30
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\PublishAdminLTEAlt::class]);
31
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\PublishAdminLTESidebar::class]);
32
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\PublishAdminLTESidebarAlt::class]);
33
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\MakeAdminUserSeeder::class]);
34
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\AdminLTEAdmin::class]);
35
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\AdminLTEAdminAlt::class]);
36
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\MakeView::class]);
37
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\AdminLTEMenu::class]);
38
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\AdminLTEMenuAlt::class]);
39
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\MakeRoute::class]);
40
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\MakeMenu::class]);
41
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\MakeV::class]);
42
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\MakeVC::class]);
43
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\MakeMVC::class]);
44
            $this->commands([\Acacha\AdminLTETemplateLaravel\Console\Username::class]);
45
        }
46
47
        $this->app->bind('AdminLTE', function () {
48
            return new \Acacha\AdminLTETemplateLaravel\AdminLTE();
49
        });
50
51
        if (config('adminlte.gravatar', true)) {
52
            $this->registerGravatarServiceProvider();
53
        }
54
55
        if (config('adminlte.guestuser', true)) {
56
            $this->registerGuestUserProvider();
57
        }
58
        if (config('auth.providers.users.field', 'email') === 'username'  &&
59
            config('adminlte.add_nullable_username', true)) {
60
            $this->loadMigrationsFrom(ADMINLTETEMPLATE_PATH .'/database/migrations/username_login');
61
        }
62
    }
63
64
    /**
65
     * Register Guest User Provider.
66
     */
67
    protected function registerGuestUserProvider()
68
    {
69
        $this->app->register(GuestUserServiceProvider::class);
70
    }
71
72
    /**
73
     * Register Gravatar Service Provider.
74
     */
75
    protected function registerGravatarServiceProvider()
76
    {
77
        $this->app->register(GravatarServiceProvider::class);
78
        if (!class_exists('Gravatar')) {
79
            class_alias(Gravatar::class, 'Gravatar');
80
        }
81
    }
82
83
    /**
84
     * Bootstrap the application services.
85
     */
86
    public function boot()
87
    {
88
        if (config('adminlte.install_routes', true)) {
89
            $this->defineRoutes();
90
        }
91
92
        //Publish
93
        $this->publishHomeController();
94
        $this->changeRegisterController();
95
        $this->changeLoginController();
96
        $this->changeForgotPasswordController();
97
        $this->publishNoGuestForgotPasswordController();
98
        $this->changeResetPasswordController();
99
        $this->publishPublicAssets();
100
        $this->publishViews();
101
        $this->publishResourceAssets();
102
        $this->publishTests();
103
        $this->publishLanguages();
104
        $this->publishGravatar();
105
        $this->publishConfig();
106
        $this->publishWebRoutes();
107
        $this->publishApiRoutes();
108
        $this->publishDusk();
109
        $this->publishDatabaseConfig();
110
111
        $this->enableSpatieMenu();
112
    }
113
114
    /**
115
     * Define the AdminLTETemplate routes.
116
     */
117
    protected function defineRoutes()
118
    {
119
        if (!$this->app->routesAreCached()) {
120
            $router = app('router');
121
122
            $router->group(['namespace' => $this->getAppNamespace().'Http\Controllers'], function () {
123
                require __DIR__.'/../Http/routes.php';
124
            });
125
        }
126
    }
127
128
    /**
129
     * Publish Home Controller.
130
     */
131
    private function publishHomeController()
132
    {
133
        $this->publishes(AdminLTE::homeController(), 'adminlte');
134
    }
135
136
    /**
137
     * Change default Laravel RegisterController.
138
     */
139
    private function changeRegisterController()
140
    {
141
        $this->publishes(AdminLTE::registerController(), 'adminlte');
142
    }
143
144
    /**
145
     * Change default Laravel LoginController.
146
     */
147
    private function changeLoginController()
148
    {
149
        $this->publishes(AdminLTE::loginController(), 'adminlte');
150
    }
151
152
    /**
153
     * Change default Laravel forgot password Controller.
154
     */
155
    private function changeForgotPasswordController()
156
    {
157
        $this->publishes(AdminLTE::forgotPasswordController(), 'adminlte');
158
    }
159
160
    /**
161
     * Publish no guest forgot password Controller.
162
     */
163
    private function publishNoGuestForgotPasswordController()
164
    {
165
        $this->publishes(AdminLTE::noGuestForgotPasswordController(), 'adminlte');
166
    }
167
168
    /**
169
     * Change default Laravel reset password Controller.
170
     */
171
    private function changeResetPasswordController()
172
    {
173
        $this->publishes(AdminLTE::resetPasswordController(), 'adminlte');
174
    }
175
176
    /**
177
     * Publish public resource assets to Laravel project.
178
     */
179
    private function publishPublicAssets()
180
    {
181
        $this->publishes(AdminLTE::publicAssets(), 'adminlte');
182
    }
183
184
    /**
185
     * Publish package views to Laravel project.
186
     */
187
    private function publishViews()
188
    {
189
        $this->loadViewsFrom(ADMINLTETEMPLATE_PATH.'/resources/views/', 'adminlte');
190
191
        $this->publishes(AdminLTE::views(), 'adminlte');
192
    }
193
194
    /**
195
     * Publish package resource assets to Laravel project.
196
     */
197
    private function publishResourceAssets()
198
    {
199
        $this->publishes(AdminLTE::resourceAssets(), 'adminlte');
200
    }
201
202
    /**
203
     * Publish package tests to Laravel project.
204
     */
205
    private function publishTests()
206
    {
207
        $this->publishes(AdminLTE::tests(), 'adminlte');
208
    }
209
210
    /**
211
     * Publish package language to Laravel project.
212
     */
213
    private function publishLanguages()
214
    {
215
        $this->loadTranslationsFrom(ADMINLTETEMPLATE_PATH.'/resources/lang/', 'adminlte_lang');
216
217
        $this->publishes(AdminLTE::languages(), 'adminlte_lang');
218
    }
219
220
    /**
221
     * Publish config Gravatar file using group.
222
     */
223
    private function publishGravatar()
224
    {
225
        $this->publishes(AdminLTE::gravatar(), 'adminlte');
226
    }
227
228
    /**
229
     * Publish adminlte package config.
230
     */
231
    private function publishConfig()
232
    {
233
        $this->publishes(AdminLTE::config(), 'adminlte');
234
    }
235
236
    /**
237
     * Publish routes/web.php file.
238
     */
239
    private function publishWebRoutes()
240
    {
241
        $this->publishes(AdminLTE::webroutes(), 'adminlte');
242
    }
243
244
    /**
245
     * Publish routes/api.php file.
246
     */
247
    private function publishApiRoutes()
248
    {
249
        $this->publishes(AdminLTE::apiroutes(), 'adminlte');
250
    }
251
252
    /**
253
     * Publish dusk tests files.
254
     */
255
    private function publishDusk()
256
    {
257
        $this->publishDuskEnvironment();
258
        $this->publishAppServiceProvider();
259
    }
260
261
    /**
262
     * Publish dusk environment files.
263
     */
264
    private function publishDuskEnvironment()
265
    {
266
        $this->publishes(AdminLTE::duskEnvironment(), 'adminlte');
267
    }
268
269
    /**
270
     * Publish app/Providers/AppServiceProvider.php file.
271
     */
272
    private function publishAppServiceProvider()
273
    {
274
        $this->publishes(AdminLTE::appServiceProviderClass(), 'adminlte');
275
    }
276
277
    /**
278
     * Publish database config files.
279
     */
280
    private function publishDatabaseConfig()
281
    {
282
        $this->publishes(AdminLTE::databaseConfig(), 'adminlte');
283
    }
284
285
    /**
286
     * Enable (if active) spatie menu.
287
     */
288
    private function enableSpatieMenu()
289
    {
290
        if ($this->app->getProvider('Spatie\Menu\Laravel\MenuServiceProvider')) {
291
            require config_path('menu.php');
292
        }
293
    }
294
}
295