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
|
|
|
/** |
20
|
|
|
* Register the package services. |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
7 |
|
public function register() |
25
|
|
|
{ |
26
|
|
|
// Bind a singleton instance of the AdminLte class into the service |
27
|
|
|
// container. |
28
|
|
|
|
29
|
|
|
$this->app->singleton(AdminLte::class, function (Container $app) { |
30
|
3 |
|
return new AdminLte( |
31
|
3 |
|
$app['config']['adminlte.filters'], |
32
|
3 |
|
$app['events'], |
33
|
3 |
|
$app |
34
|
|
|
); |
35
|
7 |
|
}); |
36
|
7 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Bootstrap the package's services. |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
7 |
|
public function boot(Factory $view, Dispatcher $events, Repository $config) |
44
|
|
|
{ |
45
|
7 |
|
$this->loadViews(); |
46
|
7 |
|
$this->loadTranslations(); |
47
|
7 |
|
$this->loadConfig(); |
48
|
7 |
|
$this->registerCommands(); |
49
|
7 |
|
$this->registerViewComposers($view); |
50
|
7 |
|
$this->registerMenu($events, $config); |
51
|
7 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Load the package views. |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
7 |
|
private function loadViews() |
59
|
|
|
{ |
60
|
7 |
|
$viewsPath = $this->packagePath('resources/views'); |
61
|
7 |
|
$this->loadViewsFrom($viewsPath, 'adminlte'); |
62
|
7 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Load the package translations. |
66
|
|
|
* |
67
|
|
|
* @return void |
68
|
|
|
*/ |
69
|
7 |
|
private function loadTranslations() |
70
|
|
|
{ |
71
|
7 |
|
$translationsPath = $this->packagePath('resources/lang'); |
72
|
7 |
|
$this->loadTranslationsFrom($translationsPath, 'adminlte'); |
73
|
7 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Load the package config. |
77
|
|
|
* |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
7 |
|
private function loadConfig() |
81
|
|
|
{ |
82
|
7 |
|
$configPath = $this->packagePath('config/adminlte.php'); |
83
|
7 |
|
$this->mergeConfigFrom($configPath, 'adminlte'); |
84
|
7 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get the absolute path to some package resource. |
88
|
|
|
* |
89
|
|
|
* @param string $path The relative path to the resource |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
7 |
|
private function packagePath($path) |
93
|
|
|
{ |
94
|
7 |
|
return __DIR__."/../$path"; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Register the package's artisan commands. |
99
|
|
|
* |
100
|
|
|
* @return void |
101
|
|
|
*/ |
102
|
7 |
|
private function registerCommands() |
103
|
|
|
{ |
104
|
7 |
|
$this->commands([ |
105
|
7 |
|
AdminLteInstallCommand::class, |
106
|
|
|
AdminLteStatusCommand::class, |
107
|
|
|
AdminLteUpdateCommand::class, |
108
|
|
|
AdminLtePluginCommand::class, |
109
|
|
|
]); |
110
|
7 |
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Register the package's view composers. |
114
|
|
|
* |
115
|
|
|
* @return void |
116
|
|
|
*/ |
117
|
7 |
|
private function registerViewComposers(Factory $view) |
118
|
|
|
{ |
119
|
7 |
|
$view->composer('adminlte::page', AdminLteComposer::class); |
120
|
7 |
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Register the menu events handlers. |
124
|
|
|
* |
125
|
|
|
* @return void |
126
|
|
|
*/ |
127
|
7 |
|
private static function registerMenu(Dispatcher $events, Repository $config) |
128
|
|
|
{ |
129
|
|
|
// Register a handler for the BuildingMenu event, this handler will add |
130
|
|
|
// the menu defined on the config file to the menu builder instance. |
131
|
|
|
|
132
|
7 |
|
$events->listen( |
133
|
7 |
|
BuildingMenu::class, |
134
|
|
|
function (BuildingMenu $event) use ($config) { |
135
|
1 |
|
$menu = $config->get('adminlte.menu', []); |
136
|
1 |
|
$menu = is_array($menu) ? $menu : []; |
137
|
1 |
|
$event->menu->add(...$menu); |
138
|
7 |
|
} |
139
|
|
|
); |
140
|
7 |
|
} |
141
|
|
|
} |
142
|
|
|
|