97 lines
2.9 KiB
PHP
97 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Concept;
|
|
use App\Models\Home;
|
|
use Illuminate\Pagination\Paginator;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Spatie\Translatable\Facades\Translatable;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Bootstrap any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
// * HTTPS FIX
|
|
URL::forceScheme('https');
|
|
|
|
// * HA PROXY FIX
|
|
App::singleton('clientIp', function () {
|
|
if (config('app.env') === 'local') {
|
|
return request()->getClientIp();
|
|
} else {
|
|
return request()->server('HTTP_X_FORWARDED_FOR') ??
|
|
request()->getClientIp();
|
|
}
|
|
});
|
|
|
|
// * LOCAL FORCE eg: for Carbon
|
|
setlocale(LC_ALL, \sprintf(
|
|
'%s_%s.UTF-8',
|
|
config('app.locale'),
|
|
\strtoupper(config('app.locale'))
|
|
));
|
|
Carbon::setLocale(config('app.locale'));
|
|
|
|
Translatable::fallback(
|
|
fallbackAny: true,
|
|
);
|
|
|
|
$this->sharetoView();
|
|
}
|
|
|
|
/**
|
|
* Share Vars to view
|
|
*
|
|
* @return void
|
|
*/
|
|
private function sharetoView()
|
|
{
|
|
if (app()->runningInConsole()) {
|
|
return;
|
|
}
|
|
|
|
// * FORCE BOOTSTRAP PAGINATOR (or custom if in front)
|
|
// Early boot, request wont be filled as expected.
|
|
if (collect(explode('/', \request()->getPathInfo()))->get(1) === 'bo') {
|
|
Paginator::useBootstrap();
|
|
} else {
|
|
Paginator::useBootstrap();
|
|
}
|
|
|
|
// * FORCE BOOTSTRAP PAGINATOR (or custom if in front)
|
|
// Early boot, request wont be filled as expected.
|
|
if (collect(explode('/', \request()->getPathInfo()))->get(1) === 'bo') {
|
|
Paginator::defaultview('bo.modules.pagination');
|
|
} else {
|
|
Paginator::defaultview('fo.modules.pagination');
|
|
}
|
|
|
|
$appInfos = Cache::remember('composer', 360, function () {
|
|
return json_decode(File::get(\app_path('../composer.json')));
|
|
});
|
|
// Share composer.json infos.
|
|
if (
|
|
isset($appInfos->name) and isset($appInfos->version) and
|
|
isset($appInfos->license) and isset($appInfos->time)
|
|
) {
|
|
View::share('cpsr_name', $appInfos->name);
|
|
View::share('cpsr_version', $appInfos->version);
|
|
View::share('cpsr_license', $appInfos->license);
|
|
View::share('cpsr_time', now()->parse($appInfos->time)->isoFormat('Y'));
|
|
}
|
|
View::share('globalHome', Home::first());
|
|
View::share('conceptsList', Concept::where('id', '<>', 1)->get());
|
|
}
|
|
}
|