ldc-supportweb/app/Providers/AppServiceProvider.php

68 lines
2 KiB
PHP
Raw Permalink Normal View History

2020-11-18 10:23:51 +01:00
<?php
namespace App\Providers;
use App\Models\MacroSchedule\Marker;
2021-04-15 16:47:57 +02:00
use Illuminate\Pagination\Paginator;
2022-08-30 13:21:07 +00:00
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
2021-07-30 00:33:18 +02:00
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\URL;
2021-05-21 16:02:29 +02:00
use Illuminate\Support\Facades\View;
2020-11-18 10:23:51 +01:00
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
2021-04-15 16:47:57 +02:00
Paginator::useBootstrap();
2022-06-09 12:03:49 +02:00
URL::forceScheme('https');
2021-05-21 16:02:29 +02:00
2022-08-30 13:21:07 +00:00
// * LOCAL FORCE eg: for Carbon
// * Remove numeric to prevent float seperator to breaking numeric transactions
\collect([\LC_TIME, \LC_MESSAGES, \LC_COLLATE, \LC_CTYPE, \LC_MONETARY])
->map(function ($contant) {
setlocale(
$contant,
\sprintf(
'%s_%s.UTF-8',
config('app.locale'),
\strtoupper(config('app.locale'))
)
);
});
Carbon::setLocale(config('app.locale'));
2021-12-04 18:53:39 +01:00
2022-08-30 13:21:07 +00:00
// * Force bootstrap paginator
Paginator::useBootstrap();
2021-07-30 00:33:18 +02:00
2022-08-30 13:21:07 +00:00
// * HA PROXY FIX
app()->singleton('clientIp', function () {
if (config('app.env') === 'local') {
return request()->getClientIp();
}
return request()->server('HTTP_X_FORWARDED_FOR') ?? request()->getClientIp();
});
if (!app()->runningInConsole()) {
$appInfos = Cache::remember('composer', 360, function () {
return json_decode(File::get(\app_path('../composer.json')));
});
View::share('name', $appInfos->name);
View::share('version', $appInfos->version);
View::share('license', $appInfos->license);
// * Groups
View::share('markerLabels', Cache::rememberForever('markerLabels', function () {
return Marker::getCachedLabels() ?? [];
}));
}//end if
2020-11-18 10:23:51 +01:00
}
}