1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Malezha\Menu; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Config\Repository; |
6
|
|
|
use Illuminate\Contracts\Container\Container; |
7
|
|
|
use Illuminate\Support\ServiceProvider; |
8
|
|
|
use Malezha\Menu\Contracts\Attributes as AttributesContract; |
9
|
|
|
use Malezha\Menu\Contracts\Builder as BuilderContract; |
10
|
|
|
use Malezha\Menu\Contracts\SubMenu as GroupContract; |
11
|
|
|
use Malezha\Menu\Contracts\Item as ItemContract; |
12
|
|
|
use Malezha\Menu\Contracts\Link as LinkContract; |
13
|
|
|
use Malezha\Menu\Contracts\Menu as MenuContract; |
14
|
|
|
use Malezha\Menu\Contracts\MenuRender; |
15
|
|
|
use Malezha\Menu\Entity\Attributes; |
16
|
|
|
use Malezha\Menu\Entity\Builder; |
17
|
|
|
use Malezha\Menu\Entity\SubMenu; |
18
|
|
|
use Malezha\Menu\Entity\Item; |
19
|
|
|
use Malezha\Menu\Entity\Link; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class MenuServiceProvider |
23
|
|
|
* @package Malezha\Menu |
24
|
|
|
*/ |
25
|
|
|
class MenuServiceProvider extends ServiceProvider |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Indicates if loading of the provider is deferred. |
29
|
|
|
* |
30
|
|
|
* @var bool |
31
|
|
|
*/ |
32
|
|
|
protected $defer = false; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Bootstrap the application services. |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
39 |
|
public function boot() |
40
|
|
|
{ |
41
|
39 |
|
$this->loadViewsFrom(__DIR__ . '/../views', 'menu'); |
42
|
|
|
|
43
|
39 |
|
$this->publishes([ |
44
|
39 |
|
__DIR__ . '/../views' => base_path('resources/views/vendor/menu'), |
45
|
39 |
|
__DIR__ . '/../config/menu.php' => config_path('menu.php'), |
46
|
39 |
|
]); |
47
|
39 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Register the application services. |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
39 |
|
public function register() |
55
|
|
|
{ |
56
|
39 |
|
$this->mergeConfigFrom(__DIR__ . '/../config/menu.php', 'menu'); |
57
|
|
|
|
58
|
39 |
|
$this->registerRenderSystem(); |
59
|
39 |
|
$this->registerAttributes(); |
60
|
39 |
|
$this->registerLink(); |
61
|
39 |
|
$this->registerBuilder(); |
62
|
39 |
|
$this->registerItem(); |
63
|
39 |
|
$this->registerGroup(); |
64
|
39 |
|
$this->registerSingleton(); |
65
|
39 |
|
} |
66
|
|
|
|
67
|
39 |
|
protected function registerSingleton() |
68
|
|
|
{ |
69
|
|
|
$this->app->singleton('menu.instance', function(Container $app) { |
70
|
6 |
|
return new Menu($app); |
71
|
39 |
|
}); |
72
|
39 |
|
$this->app->alias('menu.instance', MenuContract::class); |
73
|
39 |
|
} |
74
|
|
|
|
75
|
39 |
|
protected function registerBuilder() |
76
|
|
|
{ |
77
|
39 |
|
$this->app->bind('menu.builder', Builder::class); |
78
|
39 |
|
$this->app->alias('menu.builder', BuilderContract::class); |
79
|
39 |
|
} |
80
|
|
|
|
81
|
39 |
|
protected function registerGroup() |
82
|
|
|
{ |
83
|
39 |
|
$this->app->bind('menu.group', SubMenu::class); |
84
|
39 |
|
$this->app->alias('menu.group', GroupContract::class); |
85
|
39 |
|
} |
86
|
|
|
|
87
|
39 |
|
protected function registerItem() |
88
|
|
|
{ |
89
|
39 |
|
$this->app->bind('menu.item', Item::class); |
90
|
39 |
|
$this->app->alias('menu.item', ItemContract::class); |
91
|
39 |
|
} |
92
|
|
|
|
93
|
39 |
|
protected function registerLink() |
94
|
|
|
{ |
95
|
39 |
|
$this->app->bind('menu.link', Link::class); |
96
|
39 |
|
$this->app->alias('menu.link', LinkContract::class); |
97
|
39 |
|
} |
98
|
|
|
|
99
|
39 |
|
protected function registerAttributes() |
100
|
|
|
{ |
101
|
39 |
|
$this->app->bind('menu.attributes', Attributes::class); |
102
|
39 |
|
$this->app->alias('menu.attributes', AttributesContract::class); |
103
|
39 |
|
} |
104
|
|
|
|
105
|
|
|
protected function registerRenderSystem() |
106
|
|
|
{ |
107
|
39 |
|
$this->app->bind('menu.render', function (Container $app) { |
108
|
22 |
|
$config = $app->make(Repository::class)->get('menu'); |
109
|
22 |
|
$key = $config['default']; |
110
|
22 |
|
$available = $config['renders']; |
111
|
|
|
|
112
|
22 |
|
if (array_key_exists($key, $available)) { |
113
|
22 |
|
return new $available[$key]($app); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
throw new \Exception('Can use template system: ' . $config['default']); |
117
|
39 |
|
}); |
118
|
39 |
|
$this->app->alias('menu.render', MenuRender::class); |
119
|
39 |
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Get the services provided by the provider. |
123
|
|
|
* |
124
|
|
|
* @return array |
125
|
|
|
*/ |
126
|
|
|
public function provides() |
127
|
|
|
{ |
128
|
|
|
return []; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|