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
|
|
|
$viewsPath = $this->packagePath('resources/views'); |
51
|
|
|
$this->loadViewsFrom($viewsPath, 'adminlte'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function loadTranslations() |
55
|
|
|
{ |
56
|
|
|
$translationsPath = $this->packagePath('resources/lang'); |
57
|
|
|
|
58
|
|
|
$this->loadTranslationsFrom($translationsPath, 'adminlte'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function loadConfig() |
62
|
|
|
{ |
63
|
|
|
$configPath = $this->packagePath('config/adminlte.php'); |
64
|
|
|
|
65
|
|
|
$this->mergeConfigFrom($configPath, 'adminlte'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private function packagePath($path) |
69
|
|
|
{ |
70
|
|
|
return __DIR__."/../$path"; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
private function registerCommands() |
74
|
|
|
{ |
75
|
|
|
$this->commands(AdminLteInstallCommand::class); |
76
|
|
|
$this->commands(AdminLteStatusCommand::class); |
77
|
|
|
$this->commands(AdminLteUpdateCommand::class); |
78
|
|
|
$this->commands(AdminLtePluginCommand::class); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
private function registerViewComposers(Factory $view) |
82
|
|
|
{ |
83
|
|
|
$view->composer('adminlte::page', AdminLteComposer::class); |
84
|
|
|
} |
85
|
|
|
|
86
|
1 |
|
public static function registerMenu(Dispatcher $events, Repository $config) |
87
|
|
|
{ |
88
|
|
|
$events->listen(BuildingMenu::class, function (BuildingMenu $event) use ($config) { |
89
|
1 |
|
$menu = $config->get('adminlte.menu'); |
90
|
1 |
|
call_user_func_array([$event->menu, 'add'], $menu); |
91
|
1 |
|
}); |
92
|
1 |
|
} |
93
|
|
|
} |
94
|
|
|
|