-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServiceProvider.php
272 lines (226 loc) · 7.96 KB
/
ServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
namespace Modules\System;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use Modules\LivewireCore\Filesystem\PathResolver;
use Modules\System\Classes\PluginManager;
use Modules\System\Classes\SettingsManager;
use Modules\System\Classes\SideNavManager;
use Modules\Backend\Classes\WidgetManager;
use Arr;
use Str;
use BackendMenu;
use BackendAuth;
use Backend;
use Event;
use Livewire\Livewire;
use Modules\Backend\Models\UserRole;
use App;
use Illuminate\Foundation\AliasLoader;
class ServiceProvider extends BaseServiceProvider
{
public $pluginsPath;
public $tempPath;
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->extendArrStr();
$this->registerProvider();
$this->registerAlias();
$this->app->instance('path.plugins', $this->pluginsPath());
$this->app->instance('path.temp', $this->tempPath());
$this->registerSingletons();
PluginManager::instance()->registerAll();
if ($this->app['execution.context']=='back-end') {
$this->registerBackendNavigation();
$this->registerBackendReportWidgets();
// $this->registerBackendWidgets();
$this->registerBackendPermissions();
// $this->registerBackendSettings();
}
}
protected function extendArrStr()
{
Arr::macro('build', function(array $array, callable $callback){
$results = [];
foreach ($array as $key => $value) {
list($innerKey, $innerValue) = call_user_func($callback, $key, $value);
$results[$innerKey] = $innerValue;
}
return $results;
});
Str::macro('normalizeClassName', function ($name){
if (is_object($name)) {
$name = get_class($name);
}
$name = '\\'.ltrim($name, '\\');
return $name;
});
Str::macro('getClassId', function ($name){
if (is_object($name)) {
$name = get_class($name);
}
$name = ltrim($name, '\\');
$name = str_replace('\\', '_', $name);
return strtolower($name);
});
Str::macro('getClassNamespace', function ($name){
$name = Str::normalizeClassName($name);
return substr($name, 0, strrpos($name, "\\"));
});
Str::macro('getPrecedingSymbols', function($string, $symbol){
return strlen($string) - strlen(ltrim($string, $symbol));
});
}
protected function registerProvider()
{
$providers = include 'providers.php';
foreach ($providers as $provider){
App::register($provider);
}
}
protected function registerAlias()
{
$aliases = include 'aliases.php';
foreach ($aliases as $alias=>$class)
{
AliasLoader::getInstance()->alias($alias,$class);
}
}
/**
* Get the path to the public / web directory.
*
* @return string
*/
public function tempPath()
{
return $this->tempPath ?: PathResolver::join(base_path(), '/storage/temp');
}
/*
* Register navigation
*/
protected function registerBackendNavigation()
{
BackendMenu::registerCallback(function ($manager) {
$manager->registerMenuItems('Modules.System', [
'system' => [
'label' => 'system::lang.settings.menu_label',
'icon' => 'icon-cog',
'iconSvg' => 'modules/system/assets/images/cog-icon.svg',
'url' => Backend::url('system/system'),
'permissions' => [],
'order' => 1000
]
]);
// $manager->registerOwnerAlias('Winter.System', 'October.System');
});
$this->booting(function () {
/*
* Remove the Winter.System.system main menu item if there is no subpages to display
*/
// Event::listen('backend.menu.extendItems', function ($manager) {
// $systemSettingItems = SettingsManager::instance()->listItems('system');
// $systemMenuItems = $manager->listSideMenuItems('Modules.System', 'system');
// if (empty($systemSettingItems) && empty($systemMenuItems)) {
// $manager->removeMainMenuItem('Modules.System', 'system');
// }
// }, -9999);
Event::listen('backend.menu.extendItems', function ($manager) {
// dd(32312);
$systemSettingItems = SideNavManager::instance()->listItems('modules.system');
$systemMenuItems = $manager->listSideMenuItems('Modules.System', 'system');
if (empty($systemSettingItems) && empty($systemMenuItems)) {
$manager->removeMainMenuItem('Modules.System', 'system');
}
}, -9999);
});
}
/*
* Register report widgets
*/
protected function registerBackendReportWidgets()
{
WidgetManager::instance()->registerReportWidgets(function ($manager) {
$manager->registerReportWidget(\Modules\System\ReportWidgets\Status::class, [
'label' => 'backend::lang.dashboard.status.widget_title_default',
'context' => 'dashboard1'
]);
});
}
/**
* Register singletons
*/
protected function registerSingletons()
{
$this->app->singleton('backend.helper', function () {
return new \Modules\Backend\Helpers\Backend;
});
$this->app->singleton('backend.menu', function () {
return \Modules\Backend\Classes\NavigationManager::instance();
});
$this->app->singleton('backend.auth', function () {
return \Modules\Backend\Classes\AuthManager::instance();
});
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
// dd(Arr::class);
PluginManager::instance()->bootAll();
}
public function pluginsPath()
{
return $this->pluginsPath ?: PathResolver::join(base_path(), '/Modules');
}
/**
* Set the plugins path for the application.
*
* @param string $path
* @return $this
*/
public function setPluginsPath($path)
{
$path = PathResolver::standardize($path);
$this->pluginsPath = $path;
$this->app->instance('path.plugins', $path);
return $this;
}
/*
* Register permissions
*/
protected function registerBackendPermissions()
{
BackendAuth::registerCallback(function ($manager) {
$manager->registerPermissions('Modules.System', [
// 'system.manage_updates' => [
// 'label' => 'system::lang.permissions.manage_software_updates',
// 'tab' => 'system::lang.permissions.name',
// 'roles' => UserRole::CODE_DEVELOPER,
// ],
'system.access_logs' => [
'label' => 'system::lang.permissions.access_logs',
'tab' => 'system::lang.permissions.name',
'roles' => UserRole::CODE_DEVELOPER,
],
// 'system.manage_mail_settings' => [
// 'label' => 'system::lang.permissions.manage_mail_settings',
// 'tab' => 'system::lang.permissions.name',
// 'roles' => UserRole::CODE_DEVELOPER,
// ],
// 'system.manage_mail_templates' => [
// 'label' => 'system::lang.permissions.manage_mail_templates',
// 'tab' => 'system::lang.permissions.name',
// 'roles' => UserRole::CODE_DEVELOPER,
// ]
]);
});
}
}