1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JeroenNoten\LaravelAdminLte; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Config\Repository; |
6
|
|
|
use Illuminate\Contracts\Events\Dispatcher; |
7
|
|
|
use Illuminate\Contracts\View\Factory; |
8
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
9
|
|
|
use JeroenNoten\LaravelAdminLte\Console\MakeAdminLteCommand; |
10
|
|
|
use JeroenNoten\LaravelAdminLte\Events\BuildingMenu; |
11
|
|
|
use JeroenNoten\LaravelAdminLte\Http\ViewComposers\AdminLteComposer; |
12
|
|
|
|
13
|
|
|
class ServiceProvider extends BaseServiceProvider |
14
|
|
|
{ |
15
|
|
|
public function register() |
16
|
|
|
{ |
17
|
|
|
// |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function boot( |
21
|
|
|
Factory $view, |
22
|
|
|
Dispatcher $events, |
23
|
|
|
Repository $config |
24
|
|
|
) { |
25
|
|
|
$this->loadViews(); |
26
|
|
|
|
27
|
|
|
$this->loadTranslations(); |
28
|
|
|
|
29
|
|
|
$this->publishConfig(); |
30
|
|
|
|
31
|
|
|
$this->publishAssets(); |
32
|
|
|
|
33
|
|
|
$this->registerCommands(); |
34
|
|
|
|
35
|
|
|
$this->registerViewComposers($view); |
36
|
|
|
|
37
|
|
|
static::registerMenu($events, $config); |
38
|
|
|
} |
39
|
|
|
|
40
|
1 |
|
private function loadViews() |
41
|
|
|
{ |
42
|
|
|
$viewsPath = $this->packagePath('resources/views'); |
43
|
|
|
|
44
|
|
|
$this->loadViewsFrom($viewsPath, 'adminlte'); |
45
|
|
|
|
46
|
|
|
$this->publishes( |
47
|
|
|
[ |
48
|
|
|
$viewsPath => base_path('resources/views/vendor/adminlte'), |
49
|
1 |
|
], |
50
|
|
|
'views' |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function loadTranslations() |
55
|
|
|
{ |
56
|
|
|
$translationsPath = $this->packagePath('resources/lang'); |
57
|
|
|
|
58
|
|
|
$this->loadTranslationsFrom($translationsPath, 'adminlte'); |
59
|
|
|
|
60
|
|
|
$this->publishes( |
61
|
|
|
[ |
62
|
|
|
$translationsPath => base_path( |
63
|
|
|
'resources/lang/vendor/adminlte' |
64
|
|
|
), |
65
|
|
|
], |
66
|
|
|
'translations' |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function publishConfig() |
71
|
|
|
{ |
72
|
|
|
$configPath = $this->packagePath('config/adminlte.php'); |
73
|
|
|
|
74
|
|
|
$this->publishes( |
75
|
|
|
[ |
76
|
|
|
$configPath => config_path('adminlte.php'), |
77
|
|
|
], |
78
|
|
|
'config' |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
$this->mergeConfigFrom($configPath, 'adminlte'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
private function publishAssets() |
85
|
|
|
{ |
86
|
|
|
$this->publishes( |
87
|
|
|
[ |
88
|
|
|
$this->packagePath('resources/assets') => public_path( |
89
|
|
|
'vendor/adminlte' |
90
|
|
|
), |
91
|
|
|
], |
92
|
|
|
'assets' |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
private function packagePath($path) |
97
|
|
|
{ |
98
|
|
|
return __DIR__."/../$path"; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
private function registerCommands() |
102
|
|
|
{ |
103
|
|
|
// Laravel >=5.2 only |
104
|
|
|
if (class_exists('Illuminate\\Auth\\Console\\MakeAuthCommand')) { |
105
|
|
|
$this->commands(MakeAdminLteCommand::class); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
private function registerViewComposers(Factory $view) |
110
|
|
|
{ |
111
|
|
|
$view->composer('adminlte::page', AdminLteComposer::class); |
112
|
|
|
} |
113
|
|
|
|
114
|
1 |
|
public static function registerMenu(Dispatcher $events, Repository $config) |
115
|
|
|
{ |
116
|
1 |
|
$events->listen( |
117
|
1 |
|
BuildingMenu::class, |
118
|
1 |
|
function (BuildingMenu $event) use ($config) { |
119
|
1 |
|
$menu = $config->get('adminlte.menu'); |
120
|
1 |
|
call_user_func_array([$event->menu, 'add'], $menu); |
121
|
1 |
|
} |
122
|
1 |
|
); |
123
|
1 |
|
} |
124
|
|
|
} |
125
|
|
|
|