|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace KyleMassacre\Menus; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Foundation\AliasLoader; |
|
6
|
|
|
use Illuminate\Support\ServiceProvider; |
|
7
|
|
|
|
|
8
|
|
|
class MenusServiceProvider extends ServiceProvider |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Indicates if loading of the provider is deferred. |
|
12
|
|
|
* |
|
13
|
|
|
* @var bool |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $defer = true; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Bootstrap the application events. |
|
19
|
|
|
*/ |
|
20
|
34 |
|
public function boot() |
|
21
|
|
|
{ |
|
22
|
34 |
|
$this->registerNamespaces(); |
|
23
|
34 |
|
$this->registerMenusFile(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Require the menus file if that file is exists. |
|
28
|
|
|
*/ |
|
29
|
34 |
|
public function registerMenusFile() |
|
30
|
|
|
{ |
|
31
|
34 |
|
if (file_exists($file = app_path('Support/menus.php'))) { |
|
32
|
|
|
require $file; |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Register the service provider. |
|
38
|
|
|
*/ |
|
39
|
34 |
|
public function register() |
|
40
|
|
|
{ |
|
41
|
34 |
|
$this->registerSpatieHtmlPackage(); |
|
42
|
|
|
|
|
43
|
34 |
|
$this->app->singleton('menus', function ($app) { |
|
44
|
|
|
return new Menu($app['view'], $app['config']); |
|
45
|
34 |
|
}); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Register "spatie/laravel-html" package. |
|
50
|
|
|
*/ |
|
51
|
34 |
|
private function registerSpatieHtmlPackage() |
|
52
|
|
|
{ |
|
53
|
34 |
|
$this->app->register('Spatie\Html\HtmlServiceProvider'); |
|
54
|
|
|
|
|
55
|
34 |
|
$aliases = [ |
|
56
|
34 |
|
'HTML' => 'Spatie\Html\Facades\Html', |
|
57
|
34 |
|
'Form' => 'Spatie\Html\Facades\Form', |
|
58
|
34 |
|
]; |
|
59
|
|
|
|
|
60
|
34 |
|
AliasLoader::getInstance($aliases)->register(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get the services provided by the provider. |
|
65
|
|
|
* |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
|
|
public function provides() |
|
69
|
|
|
{ |
|
70
|
|
|
return ['menus']; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Register package's namespaces. |
|
75
|
|
|
*/ |
|
76
|
34 |
|
protected function registerNamespaces() |
|
77
|
|
|
{ |
|
78
|
34 |
|
$configPath = __DIR__ . '/../config/config.php'; |
|
79
|
34 |
|
$viewsPath = __DIR__ . '/../views'; |
|
80
|
34 |
|
$this->mergeConfigFrom($configPath, 'menus'); |
|
81
|
34 |
|
$this->loadViewsFrom($viewsPath, 'menus'); |
|
82
|
|
|
|
|
83
|
34 |
|
$this->publishes([ |
|
84
|
34 |
|
$configPath => config_path('menus.php'), |
|
85
|
34 |
|
], 'config'); |
|
86
|
|
|
|
|
87
|
34 |
|
$this->publishes([ |
|
88
|
34 |
|
$viewsPath => base_path('resources/views/vendor/nwidart/menus'), |
|
89
|
34 |
|
], 'views'); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|