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