|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Epesi\Core\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
|
6
|
|
|
use Illuminate\Support\Facades\Route; |
|
7
|
|
|
use Illuminate\Support\Facades\DB; |
|
8
|
|
|
use Epesi\Core\UI; |
|
9
|
|
|
use Epesi\Core\System\Modules\ModuleManager; |
|
10
|
|
|
use Epesi\Core\Middleware\NoCacheHeaders; |
|
11
|
|
|
use Epesi\Core\Data\Persistence\SQL; |
|
12
|
|
|
|
|
13
|
|
|
class EpesiServiceProvider extends ServiceProvider |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Booting the package. |
|
17
|
|
|
*/ |
|
18
|
|
|
public function boot() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->ensureHttps(); |
|
21
|
|
|
|
|
22
|
|
|
if (env('APP_DEBUG', false)) ModuleManager::clearCache(); |
|
23
|
|
|
|
|
24
|
|
|
Route::group(['namespace' => 'Epesi\Core', 'middleware' => 'web'], function() { |
|
25
|
|
|
Route::any('/', 'Controller@index'); |
|
26
|
|
|
Route::get('logo', 'Controller@logo'); |
|
27
|
|
|
Route::any('install', 'Controller@install'); |
|
28
|
|
|
|
|
29
|
|
|
Route::group(['middleware' => ['auth', NoCacheHeaders::class]], function() { |
|
30
|
|
|
Route::any('home', 'Controller@home')->name('home'); |
|
31
|
|
|
|
|
32
|
|
|
Route::any('view/{alias}/{method?}/{args?}', 'Controller@view'); |
|
33
|
|
|
}); |
|
34
|
|
|
}); |
|
35
|
|
|
|
|
36
|
|
|
// call boot methods on all modules |
|
37
|
|
|
ModuleManager::call('boot'); |
|
38
|
|
|
|
|
39
|
|
|
foreach (ModuleManager::collect('translations') as $path) { |
|
40
|
|
|
$this->loadJsonTranslationsFrom($path); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
// Register admin service provider if in admin mode or in console |
|
44
|
|
|
// TODO: apply access restriction to admin mode |
|
45
|
|
|
// if ($this->app->runningInConsole() || (request('admin', false) && Auth::user()->can('modify system'))) { |
|
46
|
|
|
if ($this->app->runningInConsole() || request('admin', false)) { |
|
47
|
|
|
$this->app->register(AdminServiceProvider::class); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Register the provider. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function register() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->app->singleton(UI::class); |
|
57
|
|
|
|
|
58
|
|
|
$this->app->singleton( |
|
59
|
|
|
SQL::class, |
|
60
|
|
|
function ($app) { |
|
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Database Manager |
|
63
|
|
|
* |
|
64
|
|
|
* @var \Illuminate\Database\DatabaseManager $db |
|
65
|
|
|
*/ |
|
66
|
|
|
$db = DB::getFacadeRoot(); |
|
67
|
|
|
|
|
68
|
|
|
return new SQL($db); |
|
69
|
|
|
}); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Force to set https scheme if https enabled. |
|
74
|
|
|
* |
|
75
|
|
|
* @return void |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function ensureHttps() |
|
78
|
|
|
{ |
|
79
|
|
|
if (config('epesi.https') || config('epesi.secure')) { |
|
80
|
|
|
url()->forceScheme('https'); |
|
81
|
|
|
$this->app['request']->server->set('HTTPS', true); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.