Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
AppServiceProvider
n/a
0 / 0
n/a
0 / 0
4
n/a
0 / 0
 boot
n/a
0 / 0
4
n/a
0 / 0
1<?php
2
3namespace App\Providers;
4
5use Illuminate\Cache\RateLimiting\Limit;
6use Illuminate\Http\Resources\Json\JsonResource;
7use Illuminate\Pagination\Paginator;
8use Illuminate\Support\Carbon;
9use Illuminate\Support\Facades\App;
10use Illuminate\Support\Facades\Cache;
11use Illuminate\Support\Facades\File;
12use Illuminate\Support\Facades\RateLimiter;
13use Illuminate\Support\Facades\URL;
14use Illuminate\Support\Facades\View;
15use Illuminate\Support\ServiceProvider;
16
17/**
18 * @codeCoverageIgnore
19 */
20class AppServiceProvider extends ServiceProvider
21{
22    /**
23     * Bootstrap any application services.
24     *
25     * @return void
26     */
27    public function boot()
28    {
29        // * STATS jobs Rate Limiting.
30        RateLimiter::for('stats', function () {
31            return Limit::perMinute(60)->by(2);
32        });
33
34        // ! Important pourra etre retiré quand la V1 sera supprimé
35        // empeche l'encapsulation dans data
36        JsonResource::withoutWrapping();
37
38        // * LOCAL HTTPS FIX.
39        if (!in_array(config('app.env'), ['local', 'testing'])) {
40            URL::forceScheme('https');
41        }
42        // * HA PROXY FIX.
43        App::singleton('clientIp', function () {
44            if (
45                config('app.env') === 'local'
46            ) {
47                return request()->getClientIp();
48            } else {
49                return request()->server('HTTP_X_FORWARDED_FOR') ??
50                request()->getClientIp();
51            }
52        });
53        // * LOCAL FORCE eg: for Carbon.
54        setlocale(LC_ALL, \sprintf(
55            '%s_%s.UTF-8',
56            config('app.locale'),
57            \strtoupper(config('app.locale'))
58        ));
59        Carbon::setLocale(config('app.locale'));
60        // * FORCE BOOTSTRAP PAGINATOR.
61        if (!app()->runningInConsole()) {
62            Paginator::useBootstrap();
63        }
64
65        $appInfos = Cache::remember('composer', 360, function () {
66            return json_decode(File::get(\app_path('../composer.json')));
67        });
68        View::share('name', $appInfos->name);
69        View::share('version', $appInfos->version);
70        View::share('license', $appInfos->license);
71    }
72}