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-08 16:43:44 +02:00
|
|
|
use Illuminate\Pagination\Paginator;
|
2021-09-15 10:13:51 +02:00
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
use Illuminate\Support\Facades\App;
|
2021-09-08 16:43:44 +02:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
use Illuminate\Support\Facades\File;
|
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;
|
2021-09-08 16:43:44 +02:00
|
|
|
use Illuminate\Support\Facades\View;
|
2020-12-01 17:02:10 +01:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
|
*/
|
2020-12-01 17:02:10 +01:00
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrap any application services.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function boot()
|
|
|
|
|
{
|
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);
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
// ! Important pourra etre retiré quand la V1 sera supprimé
|
2021-08-25 09:24:01 +02:00
|
|
|
// empeche 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.
|
2021-08-04 09:42:48 +02:00
|
|
|
if (!in_array(config('app.env'), ['local', 'testing'])) {
|
2021-02-28 12:04:49 +01:00
|
|
|
URL::forceScheme('https');
|
2020-12-01 17:02:10 +01:00
|
|
|
}
|
2021-12-19 15:57:24 +01:00
|
|
|
// * HA PROXY FIX.
|
2021-09-15 10:13:51 +02:00
|
|
|
App::singleton('clientIp', function () {
|
|
|
|
|
if (
|
|
|
|
|
config('app.env') === 'local'
|
|
|
|
|
) {
|
|
|
|
|
return request()->getClientIp();
|
|
|
|
|
} else {
|
|
|
|
|
return request()->server('HTTP_X_FORWARDED_FOR') ??
|
|
|
|
|
request()->getClientIp();
|
|
|
|
|
}
|
|
|
|
|
});
|
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'));
|
2021-12-19 15:57:24 +01:00
|
|
|
// * FORCE BOOTSTRAP PAGINATOR.
|
2021-09-15 10:13:51 +02:00
|
|
|
if (!app()->runningInConsole()) {
|
|
|
|
|
Paginator::useBootstrap();
|
|
|
|
|
}
|
2021-09-08 16:43:44 +02:00
|
|
|
|
|
|
|
|
$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);
|
2020-12-01 17:02:10 +01:00
|
|
|
}
|
|
|
|
|
}
|