Completed
Push — master ( fa9ba3...d6fa90 )
by Sergi Tur
14:50 queued 11:47
created

publishDatabaseConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
            $this->loadMigrationsFrom(ADMINLTETEMPLATE_PATH .'/database/migrations/username_login');
60
        }
61
    }
62
63
    /**
64
     * Register Guest User Provider.
65
     */
66
    protected function registerGuestUserProvider()
67
    {
68
        $this->app->register(GuestUserServiceProvider::class);
69
    }
70
71
    /**
72
     * Register Gravatar Service Provider.
73
     */
74
    protected function registerGravatarServiceProvider()
75
    {
76
        $this->app->register(GravatarServiceProvider::class);
77
        if (!class_exists('Gravatar')) {
78
            class_alias(Gravatar::class, 'Gravatar');
79
        }
80
    }
81
82
    /**
83
     * Bootstrap the application services.
84
     */
85 View Code Duplication
    public function boot()
0 ignored issues
show
Duplication introduced by Sergi Tur
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
    {
87
        $this->defineRoutes();
88
89
        //Publish
90
        $this->publishHomeController();
91
        $this->changeRegisterController();
92
        $this->changeLoginController();
93
        $this->changeForgotPasswordController();
94
        $this->changeResetPasswordController();
95
        $this->publishPublicAssets();
96
        $this->publishViews();
97
        $this->publishResourceAssets();
98
        $this->publishTests();
99
        $this->publishLanguages();
100
        $this->publishGravatar();
101
        $this->publishConfig();
102
        $this->publishWebRoutes();
103
        $this->publishApiRoutes();
104
        $this->publishDusk();
105
        $this->publishDatabaseConfig();
106
107
        $this->enableSpatieMenu();
108
    }
109
110
    /**
111
     * Define the AdminLTETemplate routes.
112
     */
113
    protected function defineRoutes()
114
    {
115
        if (!$this->app->routesAreCached()) {
116
            $router = app('router');
117
118
            $router->group(['namespace' => $this->getAppNamespace().'Http\Controllers'], function () {
119
                require __DIR__.'/../Http/routes.php';
120
            });
121
        }
122
    }
123
124
    /**
125
     * Publish Home Controller.
126
     */
127
    private function publishHomeController()
128
    {
129
        $this->publishes(AdminLTE::homeController(), 'adminlte');
130
    }
131
132
    /**
133
     * Change default Laravel RegisterController.
134
     */
135
    private function changeRegisterController()
136
    {
137
        $this->publishes(AdminLTE::registerController(), 'adminlte');
138
    }
139
140
    /**
141
     * Change default Laravel LoginController.
142
     */
143
    private function changeLoginController()
144
    {
145
        $this->publishes(AdminLTE::loginController(), 'adminlte');
146
    }
147
148
    /**
149
     * Change default Laravel forgot password Controller.
150
     */
151
    private function changeForgotPasswordController()
152
    {
153
        $this->publishes(AdminLTE::forgotPasswordController(), 'adminlte');
154
    }
155
156
    /**
157
     * Change default Laravel reset password Controller.
158
     */
159
    private function changeResetPasswordController()
160
    {
161
        $this->publishes(AdminLTE::resetPasswordController(), 'adminlte');
162
    }
163
164
    /**
165
     * Publish public resource assets to Laravel project.
166
     */
167
    private function publishPublicAssets()
168
    {
169
        $this->publishes(AdminLTE::publicAssets(), 'adminlte');
170
    }
171
172
    /**
173
     * Publish package views to Laravel project.
174
     */
175
    private function publishViews()
176
    {
177
        $this->loadViewsFrom(ADMINLTETEMPLATE_PATH.'/resources/views/', 'adminlte');
178
179
        $this->publishes(AdminLTE::views(), 'adminlte');
180
    }
181
182
    /**
183
     * Publish package resource assets to Laravel project.
184
     */
185
    private function publishResourceAssets()
186
    {
187
        $this->publishes(AdminLTE::resourceAssets(), 'adminlte');
188
    }
189
190
    /**
191
     * Publish package tests to Laravel project.
192
     */
193
    private function publishTests()
194
    {
195
        $this->publishes(AdminLTE::tests(), 'adminlte');
196
    }
197
198
    /**
199
     * Publish package language to Laravel project.
200
     */
201
    private function publishLanguages()
202
    {
203
        $this->loadTranslationsFrom(ADMINLTETEMPLATE_PATH.'/resources/lang/', 'adminlte_lang');
204
205
        $this->publishes(AdminLTE::languages(), 'adminlte_lang');
206
    }
207
208
    /**
209
     * Publish config Gravatar file using group.
210
     */
211
    private function publishGravatar()
212
    {
213
        $this->publishes(AdminLTE::gravatar(), 'adminlte');
214
    }
215
216
    /**
217
     * Publish adminlte package config.
218
     */
219
    private function publishConfig()
220
    {
221
        $this->publishes(AdminLTE::config(), 'adminlte');
222
    }
223
224
    /**
225
     * Publish routes/web.php file.
226
     */
227
    private function publishWebRoutes()
228
    {
229
        $this->publishes(AdminLTE::webroutes(), 'adminlte');
230
    }
231
232
    /**
233
     * Publish routes/api.php file.
234
     */
235
    private function publishApiRoutes()
236
    {
237
        $this->publishes(AdminLTE::apiroutes(), 'adminlte');
238
    }
239
240
    /**
241
     * Publish dusk tests files.
242
     */
243
    private function publishDusk()
244
    {
245
        $this->publishDuskEnvironment();
246
        $this->publishAppServiceProvider();
247
    }
248
249
    /**
250
     * Publish dusk environment files.
251
     */
252
    private function publishDuskEnvironment()
253
    {
254
        $this->publishes(AdminLTE::duskEnvironment(), 'adminlte');
255
    }
256
257
    /**
258
     * Publish app/Providers/AppServiceProvider.php file.
259
     */
260
    private function publishAppServiceProvider()
261
    {
262
        $this->publishes(AdminLTE::appServiceProviderClass(), 'adminlte');
263
    }
264
265
    /**
266
     * Publish database config files.
267
     */
268
    private function publishDatabaseConfig()
269
    {
270
        $this->publishes(AdminLTE::databaseConfig(), 'adminlte');
271
    }
272
273
    /**
274
     * Enable (if active) spatie menu.
275
     */
276
    private function enableSpatieMenu()
277
    {
278
        if ($this->app->getProvider('Spatie\Menu\Laravel\MenuServiceProvider')) {
279
            require config_path('menu.php');
280
        }
281
    }
282
}
283