2020-12-01 17:02:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2021-10-29 17:32:30 +02:00
|
|
|
use Illuminate\Cache\RateLimiting\Limit;
|
2020-12-01 17:02:10 +01:00
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
2021-09-15 10:13:51 +02:00
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
use Illuminate\Support\Facades\App;
|
2021-10-29 17:32:30 +02:00
|
|
|
use Illuminate\Support\Facades\RateLimiter;
|
2021-02-28 12:04:49 +01:00
|
|
|
use Illuminate\Support\Facades\URL;
|
2020-12-01 17:02:10 +01:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrap any application services.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2023-09-06 17:24:53 +02:00
|
|
|
public function boot(): void
|
2020-12-01 17:02:10 +01:00
|
|
|
{
|
2021-12-19 15:57:24 +01:00
|
|
|
// * STATS jobs Rate Limiting.
|
2021-10-29 17:32:30 +02:00
|
|
|
RateLimiter::for('stats', function () {
|
|
|
|
|
return Limit::perMinute(60)->by(2);
|
|
|
|
|
});
|
|
|
|
|
|
2023-10-06 15:00:42 +02:00
|
|
|
// * Empêche l'encapsulation dans data.
|
2020-12-01 17:02:10 +01:00
|
|
|
JsonResource::withoutWrapping();
|
2021-09-15 10:13:51 +02:00
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
// * LOCAL HTTPS FIX.
|
2023-06-23 13:30:45 +02:00
|
|
|
URL::forceScheme('https');
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
// * HA PROXY FIX.
|
2021-09-15 10:13:51 +02:00
|
|
|
App::singleton('clientIp', function () {
|
2023-06-23 13:30:45 +02:00
|
|
|
if (config('app.env') === 'local') {
|
2021-09-15 10:13:51 +02:00
|
|
|
return request()->getClientIp();
|
|
|
|
|
} else {
|
|
|
|
|
return request()->server('HTTP_X_FORWARDED_FOR') ??
|
2023-09-06 17:24:53 +02:00
|
|
|
request()->getClientIp();
|
2021-09-15 10:13:51 +02:00
|
|
|
}
|
|
|
|
|
});
|
2021-12-19 15:57:24 +01:00
|
|
|
// * LOCAL FORCE eg: for Carbon.
|
2021-09-15 10:13:51 +02:00
|
|
|
setlocale(LC_ALL, \sprintf(
|
|
|
|
|
'%s_%s.UTF-8',
|
|
|
|
|
config('app.locale'),
|
|
|
|
|
\strtoupper(config('app.locale'))
|
|
|
|
|
));
|
|
|
|
|
Carbon::setLocale(config('app.locale'));
|
2020-12-01 17:02:10 +01:00
|
|
|
}
|
|
|
|
|
}
|