83 lines
2.3 KiB
PHP
83 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Pagination\Paginator;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
// ! Important pourra etre retiré quand la V1 sera supprimé
|
|
// Empeche l'encapsulation dans data .
|
|
JsonResource::withoutWrapping();
|
|
|
|
// * LOCAL HTTPS FIX.
|
|
if (!in_array(config('app.env'), ['local', 'testing'])) {
|
|
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
|
|
// * Remove numeric to prevent float seperator to breaking numeric transactions
|
|
\collect([\LC_TIME, \LC_MESSAGES, \LC_COLLATE, \LC_CTYPE, \LC_MONETARY])
|
|
->map(function ($contant) {
|
|
setlocale(
|
|
$contant,
|
|
\sprintf(
|
|
'%s_%s.UTF-8',
|
|
config('app.locale'),
|
|
\strtoupper(config('app.locale'))
|
|
)
|
|
);
|
|
});
|
|
Carbon::setLocale(config('app.locale'));
|
|
|
|
// * Force bootstrap paginator
|
|
Paginator::useBootstrap();
|
|
|
|
$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);
|
|
}
|
|
}
|