|
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
|
45 |
|
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
|
|
|
$app |
|
34
|
|
|
); |
|
35
|
45 |
|
}); |
|
36
|
45 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Bootstrap the package's services. |
|
40
|
|
|
* |
|
41
|
|
|
* @return void |
|
42
|
|
|
*/ |
|
43
|
45 |
|
public function boot(Factory $view, Dispatcher $events, Repository $config) |
|
44
|
|
|
{ |
|
45
|
45 |
|
$this->loadViews(); |
|
46
|
45 |
|
$this->loadTranslations(); |
|
47
|
45 |
|
$this->loadConfig(); |
|
48
|
45 |
|
$this->registerCommands(); |
|
49
|
45 |
|
$this->registerViewComposers($view); |
|
50
|
45 |
|
$this->registerMenu($events, $config); |
|
51
|
45 |
|
$this->loadComponents(); |
|
52
|
45 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Load the package views. |
|
56
|
|
|
* |
|
57
|
|
|
* @return void |
|
58
|
|
|
*/ |
|
59
|
45 |
|
private function loadViews() |
|
60
|
|
|
{ |
|
61
|
45 |
|
$viewsPath = $this->packagePath('resources/views'); |
|
62
|
45 |
|
$this->loadViewsFrom($viewsPath, 'adminlte'); |
|
63
|
45 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Load the package translations. |
|
67
|
|
|
* |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
45 |
|
private function loadTranslations() |
|
71
|
|
|
{ |
|
72
|
45 |
|
$translationsPath = $this->packagePath('resources/lang'); |
|
73
|
45 |
|
$this->loadTranslationsFrom($translationsPath, 'adminlte'); |
|
74
|
45 |
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Load the package config. |
|
78
|
|
|
* |
|
79
|
|
|
* @return void |
|
80
|
|
|
*/ |
|
81
|
45 |
|
private function loadConfig() |
|
82
|
|
|
{ |
|
83
|
45 |
|
$configPath = $this->packagePath('config/adminlte.php'); |
|
84
|
45 |
|
$this->mergeConfigFrom($configPath, 'adminlte'); |
|
85
|
45 |
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Get the absolute path to some package resource. |
|
89
|
|
|
* |
|
90
|
|
|
* @param string $path The relative path to the resource |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
45 |
|
private function packagePath($path) |
|
94
|
|
|
{ |
|
95
|
45 |
|
return __DIR__."/../$path"; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Register the package's artisan commands. |
|
100
|
|
|
* |
|
101
|
|
|
* @return void |
|
102
|
|
|
*/ |
|
103
|
45 |
|
private function registerCommands() |
|
104
|
|
|
{ |
|
105
|
45 |
|
$this->commands([ |
|
106
|
45 |
|
AdminLteInstallCommand::class, |
|
107
|
|
|
AdminLteStatusCommand::class, |
|
108
|
|
|
AdminLteUpdateCommand::class, |
|
109
|
|
|
AdminLtePluginCommand::class, |
|
110
|
|
|
]); |
|
111
|
45 |
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Register the package's view composers. |
|
115
|
|
|
* |
|
116
|
|
|
* @return void |
|
117
|
|
|
*/ |
|
118
|
45 |
|
private function registerViewComposers(Factory $view) |
|
119
|
|
|
{ |
|
120
|
45 |
|
$view->composer('adminlte::page', AdminLteComposer::class); |
|
121
|
45 |
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Register the menu events handlers. |
|
125
|
|
|
* |
|
126
|
|
|
* @return void |
|
127
|
|
|
*/ |
|
128
|
45 |
|
private static function registerMenu(Dispatcher $events, Repository $config) |
|
129
|
|
|
{ |
|
130
|
|
|
// Register a handler for the BuildingMenu event, this handler will add |
|
131
|
|
|
// the menu defined on the config file to the menu builder instance. |
|
132
|
|
|
|
|
133
|
45 |
|
$events->listen( |
|
134
|
45 |
|
BuildingMenu::class, |
|
135
|
|
|
function (BuildingMenu $event) use ($config) { |
|
136
|
1 |
|
$menu = $config->get('adminlte.menu', []); |
|
137
|
1 |
|
$menu = is_array($menu) ? $menu : []; |
|
138
|
1 |
|
$event->menu->add(...$menu); |
|
139
|
45 |
|
} |
|
140
|
|
|
); |
|
141
|
45 |
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Load the blade view components. |
|
145
|
|
|
* |
|
146
|
|
|
* @return void |
|
147
|
|
|
*/ |
|
148
|
45 |
|
private function loadComponents() |
|
149
|
|
|
{ |
|
150
|
|
|
// Support of x-components is only available for Laravel >= 7.x |
|
151
|
|
|
// versions. So, we check if we can load components. |
|
152
|
|
|
|
|
153
|
45 |
|
$canLoadComponents = method_exists( |
|
154
|
45 |
|
'Illuminate\Support\ServiceProvider', |
|
155
|
45 |
|
'loadViewComponentsAs' |
|
156
|
|
|
); |
|
157
|
|
|
|
|
158
|
45 |
|
if (! $canLoadComponents) { |
|
159
|
|
|
return; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
// Form components. |
|
163
|
|
|
|
|
164
|
45 |
|
$this->loadViewComponentsAs('adminlte', [ |
|
165
|
45 |
|
Components\Button::class, |
|
166
|
|
|
Components\DateRange::class, |
|
167
|
|
|
Components\Input::class, |
|
168
|
|
|
Components\InputColor::class, |
|
169
|
|
|
Components\InputDate::class, |
|
170
|
|
|
Components\InputFile::class, |
|
171
|
|
|
Components\InputSlider::class, |
|
172
|
|
|
Components\InputSwitch::class, |
|
173
|
|
|
Components\InputTag::class, |
|
174
|
|
|
Components\Select::class, |
|
175
|
|
|
Components\Select2::class, |
|
176
|
|
|
Components\SelectBs::class, |
|
177
|
|
|
Components\Textarea::class, |
|
178
|
|
|
Components\TextEditor::class, |
|
179
|
|
|
]); |
|
180
|
|
|
|
|
181
|
|
|
// Widgets components. |
|
182
|
|
|
|
|
183
|
45 |
|
$this->loadViewComponentsAs('adminlte', [ |
|
184
|
45 |
|
Components\Alert::class, |
|
185
|
|
|
Components\Callout::class, |
|
186
|
|
|
Components\Card::class, |
|
187
|
|
|
Components\Datatable::class, |
|
188
|
|
|
Components\InfoBox::class, |
|
189
|
|
|
Components\Modal::class, |
|
190
|
|
|
Components\ProfileFlat::class, |
|
191
|
|
|
Components\ProfileFlatItem::class, |
|
192
|
|
|
Components\ProfileWidget::class, |
|
193
|
|
|
Components\ProfileWidgetItem::class, |
|
194
|
|
|
Components\Progress::class, |
|
195
|
|
|
Components\SmallBox::class, |
|
196
|
|
|
]); |
|
197
|
45 |
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|