ldc-gen-game-web/app/Providers/AppServiceProvider.php

57 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2020-10-21 15:26:21 +02:00
<?php
2026-10-02 12:09:46 +02:00
declare(strict_types=1);
2020-10-21 15:26:21 +02:00
namespace App\Providers;
2020-10-29 15:40:23 +01:00
use App\Models\Settings;
2026-10-02 12:09:46 +02:00
use ErrorException;
2023-11-23 17:31:28 +01:00
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
2026-10-02 12:09:46 +02:00
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\URL;
2023-08-21 10:15:14 +00:00
use Illuminate\Support\Pluralizer;
2020-10-21 15:26:21 +02:00
use Illuminate\Support\ServiceProvider;
2026-10-02 12:09:46 +02:00
use IPLib\Factory;
2020-10-21 15:26:21 +02:00
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*/
2026-10-02 12:09:46 +02:00
public function boot(): void
2020-10-21 15:26:21 +02:00
{
2026-10-02 12:09:46 +02:00
Model::shouldBeStrict(! $this->app->environment('production'));
2023-11-23 17:31:28 +01:00
// * HTTPS FIX
2022-05-02 14:30:59 +02:00
URL::forceScheme('https');
2022-08-11 10:03:16 +02:00
// * HA PROXY FIX.
App::singleton('clientIp', function () {
2023-08-21 10:22:07 +02:00
if (config('app.env') === 'local') {
2026-10-02 12:09:46 +02:00
return Factory::parseAddressString(request()->getClientIp());
}
2026-10-02 12:09:46 +02:00
return Factory::parseAddressString(
request()->server('HTTP_X_FORWARDED_FOR') ?? request()->getClientIp()
);
});
2023-08-21 10:22:07 +02:00
2023-11-23 17:31:28 +01:00
// * LOCAL FORCE eg: for Carbon
setlocale(LC_ALL, \sprintf(
'%s_%s.UTF-8',
config('app.locale'),
\strtoupper(config('app.locale'))
));
2026-10-02 12:09:46 +02:00
Date::setLocale(config('app.locale'));
2023-08-21 10:15:14 +00:00
Pluralizer::useLanguage('french');
// * Settings Provider
app()->singleton(Settings::class, function () {
2026-10-02 12:09:46 +02:00
throw_unless($settings = Settings::getCached()->first(), ErrorException::class, 'Settings not found in DB');
return $settings;
});
2020-10-21 15:26:21 +02:00
}
}