ldc-wenn-dann-mit-respekt/app/Providers/AppServiceProvider.php

64 lines
1.6 KiB
PHP
Raw Normal View History

2022-11-18 12:39:03 +01:00
<?php
namespace App\Providers;
2023-03-15 10:31:55 +01:00
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\App;
2022-11-18 12:39:03 +01:00
use Illuminate\Support\Facades\URL;
2023-03-15 10:31:55 +01:00
use Illuminate\Support\ServiceProvider;
2022-11-18 12:39:03 +01:00
class AppServiceProvider extends ServiceProvider
{
/**
2023-03-15 10:31:55 +01:00
* Bootstrap any application services.
2022-11-18 12:39:03 +01:00
*
* @return void
*/
2023-03-15 10:31:55 +01:00
public function boot()
2022-11-18 12:39:03 +01:00
{
2023-03-15 10:31:55 +01:00
// * 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'));
$this->sharetoView();
2022-11-18 12:39:03 +01:00
}
/**
2023-03-15 10:31:55 +01:00
* Share Vars to view
2022-11-18 12:39:03 +01:00
*
* @return void
*/
2023-03-15 10:31:55 +01:00
private function sharetoView()
2022-11-18 12:39:03 +01:00
{
2023-03-15 10:31:55 +01:00
if (!app()->runningInConsole()) {
// * 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 {
// FIXME: change this if needed.
Paginator::useBootstrap();
// Paginator::defaultview('fo.modules.pagination'); .
}
}
2022-11-18 12:39:03 +01:00
}
}