Completed
Push — master ( bd1796...39e185 )
by Sergi Tur
06:06
created

publishResourceAssets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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