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\ServiceProvider as BaseServiceProvider; |
10
|
|
|
use JeroenNoten\LaravelAdminLte\Console\AdminLteInstallCommand; |
11
|
|
|
use JeroenNoten\LaravelAdminLte\Console\AdminLtePluginCommand; |
12
|
|
|
use JeroenNoten\LaravelAdminLte\Console\AdminLteStatusCommand; |
13
|
|
|
use JeroenNoten\LaravelAdminLte\Console\AdminLteUpdateCommand; |
14
|
|
|
use JeroenNoten\LaravelAdminLte\Events\BuildingMenu; |
15
|
|
|
use JeroenNoten\LaravelAdminLte\Http\ViewComposers\AdminLteComposer; |
16
|
|
|
|
17
|
|
|
class AdminLteServiceProvider extends BaseServiceProvider |
18
|
|
|
{ |
19
|
|
|
public function register() |
20
|
|
|
{ |
21
|
|
|
$this->app->singleton(AdminLte::class, function (Container $app) { |
22
|
|
|
return new AdminLte( |
23
|
|
|
$app['config']['adminlte.filters'], |
24
|
|
|
$app['events'], |
25
|
|
|
$app |
26
|
|
|
); |
27
|
|
|
}); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function boot( |
31
|
|
|
Factory $view, |
32
|
|
|
Dispatcher $events, |
33
|
|
|
Repository $config |
34
|
|
|
) { |
35
|
|
|
$this->loadViews(); |
36
|
|
|
|
37
|
|
|
$this->loadTranslations(); |
38
|
|
|
|
39
|
|
|
$this->loadConfig(); |
40
|
|
|
|
41
|
|
|
$this->registerCommands(); |
42
|
|
|
|
43
|
|
|
$this->registerViewComposers($view); |
44
|
|
|
|
45
|
|
|
static::registerMenu($events, $config); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function loadViews() |
49
|
|
|
{ |
50
|
|
|
$viewsPathUser = resource_path('views/vendor/jeroennoten/laravel-adminlte'); |
51
|
|
|
$this->loadViewsFrom($viewsPathUser, 'adminlte'); |
52
|
|
|
$viewsPath = $this->packagePath('resources/views'); |
53
|
|
|
$this->loadViewsFrom($viewsPath, 'adminlte'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function loadTranslations() |
57
|
|
|
{ |
58
|
|
|
$translationsPath = $this->packagePath('resources/lang'); |
59
|
|
|
|
60
|
|
|
$this->loadTranslationsFrom($translationsPath, 'adminlte'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private function loadConfig() |
64
|
|
|
{ |
65
|
|
|
$configPath = $this->packagePath('config/adminlte.php'); |
66
|
|
|
|
67
|
|
|
$this->mergeConfigFrom($configPath, 'adminlte'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function packagePath($path) |
71
|
|
|
{ |
72
|
|
|
return __DIR__."/../$path"; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function registerCommands() |
76
|
|
|
{ |
77
|
|
|
$this->commands(AdminLteInstallCommand::class); |
78
|
|
|
$this->commands(AdminLteStatusCommand::class); |
79
|
|
|
$this->commands(AdminLteUpdateCommand::class); |
80
|
|
|
$this->commands(AdminLtePluginCommand::class); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
private function registerViewComposers(Factory $view) |
84
|
|
|
{ |
85
|
|
|
$view->composer('adminlte::page', AdminLteComposer::class); |
86
|
|
|
} |
87
|
|
|
|
88
|
1 |
|
public static function registerMenu(Dispatcher $events, Repository $config) |
89
|
|
|
{ |
90
|
|
|
$events->listen(BuildingMenu::class, function (BuildingMenu $event) use ($config) { |
91
|
1 |
|
$menu = $config->get('adminlte.menu'); |
92
|
1 |
|
call_user_func_array([$event->menu, 'add'], $menu); |
93
|
1 |
|
}); |
94
|
1 |
|
} |
95
|
|
|
} |
96
|
|
|
|