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\Facades\Blade; |
10
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
11
|
|
|
use JeroenNoten\LaravelAdminLte\Console\AdminLteInstallCommand; |
12
|
|
|
use JeroenNoten\LaravelAdminLte\Console\AdminLtePluginCommand; |
13
|
|
|
use JeroenNoten\LaravelAdminLte\Console\AdminLteStatusCommand; |
14
|
|
|
use JeroenNoten\LaravelAdminLte\Console\AdminLteUpdateCommand; |
15
|
|
|
use JeroenNoten\LaravelAdminLte\Events\BuildingMenu; |
16
|
|
|
use JeroenNoten\LaravelAdminLte\Http\ViewComposers\AdminLteComposer; |
17
|
|
|
|
18
|
|
|
class AdminLteServiceProvider extends BaseServiceProvider |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Register the package services. |
22
|
|
|
* |
23
|
|
|
* @return void |
24
|
29 |
|
*/ |
25
|
|
|
public function register() |
26
|
|
|
{ |
27
|
|
|
// Bind a singleton instance of the AdminLte class into the service |
28
|
|
|
// container. |
29
|
|
|
|
30
|
3 |
|
$this->app->singleton(AdminLte::class, function (Container $app) { |
31
|
3 |
|
return new AdminLte( |
32
|
3 |
|
$app['config']['adminlte.filters'], |
33
|
|
|
$app['events'], |
34
|
|
|
$app |
35
|
29 |
|
); |
36
|
29 |
|
}); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Bootstrap the package's services. |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
29 |
|
*/ |
44
|
|
|
public function boot(Factory $view, Dispatcher $events, Repository $config) |
45
|
29 |
|
{ |
46
|
29 |
|
$this->loadViews(); |
47
|
29 |
|
$this->loadTranslations(); |
48
|
29 |
|
$this->loadConfig(); |
49
|
29 |
|
$this->registerCommands(); |
50
|
29 |
|
$this->registerViewComposers($view); |
51
|
29 |
|
$this->registerMenu($events, $config); |
52
|
|
|
$this->loadComponents(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Load the package views. |
57
|
|
|
* |
58
|
29 |
|
* @return void |
59
|
|
|
*/ |
60
|
29 |
|
private function loadViews() |
61
|
29 |
|
{ |
62
|
29 |
|
$viewsPath = $this->packagePath('resources/views'); |
63
|
|
|
$this->loadViewsFrom($viewsPath, 'adminlte'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Load the package translations. |
68
|
|
|
* |
69
|
29 |
|
* @return void |
70
|
|
|
*/ |
71
|
29 |
|
private function loadTranslations() |
72
|
29 |
|
{ |
73
|
29 |
|
$translationsPath = $this->packagePath('resources/lang'); |
74
|
|
|
$this->loadTranslationsFrom($translationsPath, 'adminlte'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Load the package config. |
79
|
|
|
* |
80
|
29 |
|
* @return void |
81
|
|
|
*/ |
82
|
29 |
|
private function loadConfig() |
83
|
29 |
|
{ |
84
|
29 |
|
$configPath = $this->packagePath('config/adminlte.php'); |
85
|
|
|
$this->mergeConfigFrom($configPath, 'adminlte'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get the absolute path to some package resource. |
90
|
|
|
* |
91
|
|
|
* @param string $path The relative path to the resource |
92
|
29 |
|
* @return string |
93
|
|
|
*/ |
94
|
29 |
|
private function packagePath($path) |
95
|
|
|
{ |
96
|
|
|
return __DIR__."/../$path"; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Register the package's artisan commands. |
101
|
|
|
* |
102
|
29 |
|
* @return void |
103
|
|
|
*/ |
104
|
29 |
|
private function registerCommands() |
105
|
29 |
|
{ |
106
|
|
|
$this->commands([ |
107
|
|
|
AdminLteInstallCommand::class, |
108
|
|
|
AdminLteStatusCommand::class, |
109
|
|
|
AdminLteUpdateCommand::class, |
110
|
29 |
|
AdminLtePluginCommand::class, |
111
|
|
|
]); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Register the package's view composers. |
116
|
|
|
* |
117
|
29 |
|
* @return void |
118
|
|
|
*/ |
119
|
29 |
|
private function registerViewComposers(Factory $view) |
120
|
29 |
|
{ |
121
|
|
|
$view->composer('adminlte::page', AdminLteComposer::class); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Register the menu events handlers. |
126
|
|
|
* |
127
|
29 |
|
* @return void |
128
|
|
|
*/ |
129
|
|
|
private static function registerMenu(Dispatcher $events, Repository $config) |
130
|
|
|
{ |
131
|
|
|
// Register a handler for the BuildingMenu event, this handler will add |
132
|
29 |
|
// the menu defined on the config file to the menu builder instance. |
133
|
29 |
|
|
134
|
|
|
$events->listen( |
135
|
1 |
|
BuildingMenu::class, |
136
|
1 |
|
function (BuildingMenu $event) use ($config) { |
137
|
1 |
|
$menu = $config->get('adminlte.menu', []); |
138
|
29 |
|
$menu = is_array($menu) ? $menu : []; |
139
|
|
|
$event->menu->add(...$menu); |
140
|
29 |
|
} |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Load the Components. |
146
|
|
|
* |
147
|
|
|
* @return void |
148
|
|
|
*/ |
149
|
|
|
private function loadComponents() |
150
|
|
|
{ |
151
|
|
|
/** |
152
|
|
|
* FORM COMPONENTS. |
153
|
|
|
*/ |
154
|
|
|
Blade::component('adminlte-input', Components\Input::class); |
155
|
|
|
Blade::component('adminlte-input-file', Components\InputFile::class); |
156
|
|
|
Blade::component('adminlte-input-color', Components\InputColor::class); |
157
|
|
|
Blade::component('adminlte-input-date', Components\InputDate::class); |
158
|
|
|
Blade::component('adminlte-textarea', Components\Textarea::class); |
159
|
|
|
Blade::component('adminlte-select', Components\Select::class); |
160
|
|
|
Blade::component('adminlte-select2', Components\Select2::class); |
161
|
|
|
Blade::component('adminlte-select-icon', Components\SelectIcon::class); |
162
|
|
|
Blade::component('adminlte-option', Components\Option::class); |
163
|
|
|
Blade::component('adminlte-input-switch', Components\InputSwitch::class); |
164
|
|
|
Blade::component('adminlte-input-tag', Components\InputTag::class); |
165
|
|
|
Blade::component('adminlte-submit', Components\Submit::class); |
166
|
|
|
Blade::component('adminlte-text-editor', Components\TextEditor::class); |
167
|
|
|
Blade::component('adminlte-date-range', Components\DateRange::class); |
168
|
|
|
Blade::component('adminlte-input-slider', Components\InputSlider::class); |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* WIDGETS. |
172
|
|
|
*/ |
173
|
|
|
Blade::component('adminlte-card', Components\Card::class); |
174
|
|
|
Blade::component('adminlte-info-box', Components\InfoBox::class); |
175
|
|
|
Blade::component('adminlte-small-box', Components\SmallBox::class); |
176
|
|
|
Blade::component('adminlte-profile-flat', Components\ProfileFlat::class); |
177
|
|
|
Blade::component('adminlte-profile-flat-item', Components\ProfileFlatItem::class); |
178
|
|
|
Blade::component('adminlte-profile-widget', Components\ProfileWidget::class); |
179
|
|
|
Blade::component('adminlte-profile-widget-item', Components\ProfileWidgetItem::class); |
180
|
|
|
Blade::component('adminlte-alert', Components\Alert::class); |
181
|
|
|
Blade::component('adminlte-callout', Components\Callout::class); |
182
|
|
|
Blade::component('adminlte-progress', Components\Progress::class); |
183
|
|
|
Blade::component('adminlte-modal', Components\Modal::class); |
184
|
|
|
Blade::component('adminlte-datatable', Components\Datatable::class); |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|