ldc-jeusselin/app/Providers/AppServiceProvider.php

85 lines
2.4 KiB
PHP
Raw Permalink Normal View History

2021-02-11 11:24:44 +01:00
<?php
namespace App\Providers;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Pagination\Paginator;
2021-02-23 09:40:21 +01:00
use Illuminate\Support\Facades\URL;
2021-02-11 11:24:44 +01:00
use Illuminate\Support\ServiceProvider;
2021-03-23 12:19:28 +01:00
use Illuminate\Support\Facades\View;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\App;
2021-02-11 11:24:44 +01:00
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// Prevent lazy loading, but only when the app is not in production.
Model::preventLazyLoading(config('app.env') !== 'production');
// * HTTPS FIX
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
setlocale(LC_ALL, \sprintf(
'%s_%s.UTF-8',
config('app.locale'),
\strtoupper(config('app.locale'))
));
Carbon::setLocale(config('app.locale'));
// * FORCE BOOTSTRAP PAGINATOR (or custom if in front)
Paginator::useBootstrap();
2021-03-23 12:19:28 +01:00
$today = Carbon::now();
2021-03-30 17:49:54 +02:00
// * Current time
$start_winter = Carbon::create($today->year, 12, 21, 0, 0, 0);
$start_spring = Carbon::create($today->year, 3, 20, 0, 0, 0);
$start_spring_nextyear = Carbon::create($today->year + 1, 3, 20, 0, 0, 0);
$start_summer = Carbon::create($today->year, 6, 21, 0, 0, 0);
$start_fall = Carbon::create($today->year, 9, 22, 0, 0, 0);
2021-03-23 12:19:28 +01:00
// * Default
2022-01-03 09:12:04 +01:00
$saison_css = "winter";
2021-12-21 08:39:30 +01:00
if ($today->between($start_winter, $start_spring_nextyear, true)) {
2021-03-23 12:19:28 +01:00
$saison_css = "winter";
}
if ($today->between($start_spring, $start_summer, true)) {
$saison_css = "spring";
}
if ($today->between($start_summer, $start_fall, true)) {
$saison_css = "summer";
}
if ($today->between($start_fall, $start_winter, true)) {
$saison_css = "fall";
}
View::share('saison_css', $saison_css);
2021-02-11 11:24:44 +01:00
}
}