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