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