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