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\Facades\Route; |
10
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
11
|
|
|
use JeroenNoten\LaravelAdminLte\Console\AdminLteInstallCommand; |
12
|
|
|
use JeroenNoten\LaravelAdminLte\Console\AdminLtePluginCommand; |
13
|
|
|
use JeroenNoten\LaravelAdminLte\Console\AdminLteStatusCommand; |
14
|
|
|
use JeroenNoten\LaravelAdminLte\Console\AdminLteUpdateCommand; |
15
|
|
|
use JeroenNoten\LaravelAdminLte\Events\BuildingMenu; |
16
|
|
|
use JeroenNoten\LaravelAdminLte\Http\ViewComposers\AdminLteComposer; |
17
|
|
|
use JeroenNoten\LaravelAdminLte\View\Components\Form; |
18
|
|
|
use JeroenNoten\LaravelAdminLte\View\Components\Layout; |
19
|
|
|
use JeroenNoten\LaravelAdminLte\View\Components\Tool; |
20
|
|
|
use JeroenNoten\LaravelAdminLte\View\Components\Widget; |
21
|
|
|
|
22
|
|
|
class AdminLteServiceProvider extends BaseServiceProvider |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* The prefix to use for register/load the package resources. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $pkgPrefix = 'adminlte'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Array with the available layout components. |
33
|
|
|
* |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
protected $layoutComponents = [ |
37
|
|
|
'navbar-darkmode-widget' => Layout\NavbarDarkmodeWidget::class, |
38
|
|
|
'navbar-notification' => Layout\NavbarNotification::class, |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Array with the available form components. |
43
|
|
|
* |
44
|
|
|
* @var array |
45
|
|
|
*/ |
46
|
|
|
protected $formComponents = [ |
47
|
|
|
'button' => Form\Button::class, |
48
|
|
|
'date-range' => Form\DateRange::class, |
49
|
|
|
'input' => Form\Input::class, |
50
|
|
|
'input-color' => Form\InputColor::class, |
51
|
|
|
'input-date' => Form\InputDate::class, |
52
|
|
|
'input-file' => Form\InputFile::class, |
53
|
|
|
'input-slider' => Form\InputSlider::class, |
54
|
|
|
'input-switch' => Form\InputSwitch::class, |
55
|
|
|
'options' => Form\Options::class, |
56
|
|
|
'select' => Form\Select::class, |
57
|
|
|
'select2' => Form\Select2::class, |
58
|
|
|
'select-bs' => Form\SelectBs::class, |
59
|
|
|
'textarea' => Form\Textarea::class, |
60
|
|
|
'text-editor' => Form\TextEditor::class, |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Array with the available tool components. |
65
|
|
|
* |
66
|
|
|
* @var array |
67
|
|
|
*/ |
68
|
|
|
protected $toolComponents = [ |
69
|
|
|
'datatable' => Tool\Datatable::class, |
70
|
|
|
'modal' => Tool\Modal::class, |
71
|
|
|
]; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Array with the available widget components. |
75
|
|
|
* |
76
|
|
|
* @var array |
77
|
|
|
*/ |
78
|
|
|
protected $widgetComponents = [ |
79
|
|
|
'alert' => Widget\Alert::class, |
80
|
|
|
'callout' => Widget\Callout::class, |
81
|
|
|
'card' => Widget\Card::class, |
82
|
|
|
'info-box' => Widget\InfoBox::class, |
83
|
|
|
'profile-col-item' => Widget\ProfileColItem::class, |
84
|
|
|
'profile-row-item' => Widget\ProfileRowItem::class, |
85
|
|
|
'profile-widget' => Widget\ProfileWidget::class, |
86
|
|
|
'progress' => Widget\Progress::class, |
87
|
|
|
'small-box' => Widget\SmallBox::class, |
88
|
|
|
]; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Register the package services. |
92
|
|
|
* |
93
|
|
|
* @return void |
94
|
|
|
*/ |
95
|
181 |
|
public function register() |
96
|
|
|
{ |
97
|
|
|
// Bind a singleton instance of the AdminLte class into the service |
98
|
|
|
// container. |
99
|
|
|
|
100
|
181 |
|
$this->app->singleton(AdminLte::class, function (Container $app) { |
101
|
3 |
|
return new AdminLte( |
102
|
3 |
|
$app['config']['adminlte.filters'], |
103
|
3 |
|
$app['events'], |
104
|
|
|
$app |
105
|
|
|
); |
106
|
181 |
|
}); |
107
|
181 |
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Bootstrap the package's services. |
111
|
|
|
* |
112
|
|
|
* @return void |
113
|
|
|
*/ |
114
|
181 |
|
public function boot(Factory $view, Dispatcher $events, Repository $config) |
115
|
|
|
{ |
116
|
181 |
|
$this->loadViews(); |
117
|
181 |
|
$this->loadTranslations(); |
118
|
181 |
|
$this->loadConfig(); |
119
|
181 |
|
$this->registerCommands(); |
120
|
181 |
|
$this->registerViewComposers($view); |
121
|
181 |
|
$this->registerMenu($events, $config); |
122
|
181 |
|
$this->loadComponents(); |
123
|
181 |
|
$this->loadRoutes(); |
124
|
181 |
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Load the package views. |
128
|
|
|
* |
129
|
|
|
* @return void |
130
|
|
|
*/ |
131
|
181 |
|
private function loadViews() |
132
|
|
|
{ |
133
|
181 |
|
$viewsPath = $this->packagePath('resources/views'); |
134
|
181 |
|
$this->loadViewsFrom($viewsPath, $this->pkgPrefix); |
135
|
181 |
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Load the package translations. |
139
|
|
|
* |
140
|
|
|
* @return void |
141
|
|
|
*/ |
142
|
181 |
|
private function loadTranslations() |
143
|
|
|
{ |
144
|
181 |
|
$translationsPath = $this->packagePath('resources/lang'); |
145
|
181 |
|
$this->loadTranslationsFrom($translationsPath, $this->pkgPrefix); |
146
|
181 |
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Load the package config. |
150
|
|
|
* |
151
|
|
|
* @return void |
152
|
|
|
*/ |
153
|
181 |
|
private function loadConfig() |
154
|
|
|
{ |
155
|
181 |
|
$configPath = $this->packagePath('config/adminlte.php'); |
156
|
181 |
|
$this->mergeConfigFrom($configPath, $this->pkgPrefix); |
157
|
181 |
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Get the absolute path to some package resource. |
161
|
|
|
* |
162
|
|
|
* @param string $path The relative path to the resource |
163
|
|
|
* @return string |
164
|
|
|
*/ |
165
|
181 |
|
private function packagePath($path) |
166
|
|
|
{ |
167
|
181 |
|
return __DIR__."/../$path"; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Register the package's artisan commands. |
172
|
|
|
* |
173
|
|
|
* @return void |
174
|
|
|
*/ |
175
|
181 |
|
private function registerCommands() |
176
|
|
|
{ |
177
|
181 |
|
$this->commands([ |
178
|
181 |
|
AdminLteInstallCommand::class, |
179
|
|
|
AdminLteStatusCommand::class, |
180
|
|
|
AdminLteUpdateCommand::class, |
181
|
|
|
AdminLtePluginCommand::class, |
182
|
|
|
]); |
183
|
181 |
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Register the package's view composers. |
187
|
|
|
* |
188
|
|
|
* @return void |
189
|
|
|
*/ |
190
|
181 |
|
private function registerViewComposers(Factory $view) |
191
|
|
|
{ |
192
|
181 |
|
$view->composer('adminlte::page', AdminLteComposer::class); |
193
|
181 |
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Register the menu events handlers. |
197
|
|
|
* |
198
|
|
|
* @return void |
199
|
|
|
*/ |
200
|
181 |
|
private static function registerMenu(Dispatcher $events, Repository $config) |
201
|
|
|
{ |
202
|
|
|
// Register a handler for the BuildingMenu event, this handler will add |
203
|
|
|
// the menu defined on the config file to the menu builder instance. |
204
|
|
|
|
205
|
181 |
|
$events->listen( |
206
|
181 |
|
BuildingMenu::class, |
207
|
181 |
|
function (BuildingMenu $event) use ($config) { |
208
|
1 |
|
$menu = $config->get('adminlte.menu', []); |
209
|
1 |
|
$menu = is_array($menu) ? $menu : []; |
210
|
1 |
|
$event->menu->add(...$menu); |
211
|
181 |
|
} |
212
|
|
|
); |
213
|
181 |
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Load the blade view components. |
217
|
|
|
* |
218
|
|
|
* @return void |
219
|
|
|
*/ |
220
|
181 |
|
private function loadComponents() |
221
|
|
|
{ |
222
|
|
|
// Support of x-components is only available for Laravel >= 7.x |
223
|
|
|
// versions. So, we check if we can load components. |
224
|
|
|
|
225
|
181 |
|
$canLoadComponents = method_exists( |
226
|
181 |
|
'Illuminate\Support\ServiceProvider', |
227
|
181 |
|
'loadViewComponentsAs' |
228
|
|
|
); |
229
|
|
|
|
230
|
181 |
|
if (! $canLoadComponents) { |
231
|
|
|
return; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
// Load all the blade-x components. |
235
|
|
|
|
236
|
181 |
|
$components = array_merge( |
237
|
181 |
|
$this->layoutComponents, |
238
|
181 |
|
$this->formComponents, |
239
|
181 |
|
$this->toolComponents, |
240
|
181 |
|
$this->widgetComponents |
241
|
|
|
); |
242
|
|
|
|
243
|
181 |
|
$this->loadViewComponentsAs($this->pkgPrefix, $components); |
244
|
181 |
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Load the package web routes. |
248
|
|
|
* |
249
|
|
|
* @return void |
250
|
|
|
*/ |
251
|
181 |
|
private function loadRoutes() |
252
|
|
|
{ |
253
|
|
|
$routesCfg = [ |
254
|
181 |
|
'as' => "{$this->pkgPrefix}.", |
255
|
181 |
|
'prefix' => $this->pkgPrefix, |
256
|
|
|
'middleware' => ['web'], |
257
|
|
|
]; |
258
|
|
|
|
259
|
181 |
|
Route::group($routesCfg, function () { |
260
|
181 |
|
$routesPath = $this->packagePath('routes/web.php'); |
261
|
181 |
|
$this->loadRoutesFrom($routesPath); |
262
|
181 |
|
}); |
263
|
181 |
|
} |
264
|
|
|
} |
265
|
|
|
|