2020-07-23 10:29:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2021-09-16 19:31:57 +02:00
|
|
|
use App\Models\Actu;
|
2020-11-24 14:35:22 +01:00
|
|
|
use App\Models\Articles;
|
2021-09-20 23:23:46 +02:00
|
|
|
use App\Models\GeneralConfig;
|
2020-11-04 15:07:21 +01:00
|
|
|
use App\Models\Moments;
|
2021-09-15 14:25:12 +02:00
|
|
|
use Carbon\Carbon;
|
2021-10-13 14:30:01 +02:00
|
|
|
use Illuminate\Pagination\Paginator;
|
2021-09-15 14:25:12 +02:00
|
|
|
use Illuminate\Support\Facades\App;
|
2021-09-24 00:18:02 +02:00
|
|
|
use Illuminate\Support\Facades\Blade;
|
2021-07-22 09:31:34 +02:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2021-03-21 22:51:19 +01:00
|
|
|
use Illuminate\Support\Facades\URL;
|
2020-11-04 15:07:21 +01:00
|
|
|
use Illuminate\Support\Facades\View;
|
2020-07-23 10:29:36 +02:00
|
|
|
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()
|
|
|
|
|
{
|
2021-09-15 14:25:12 +02:00
|
|
|
// LOCAL HTTPS FIX
|
2021-03-16 15:59:03 +01:00
|
|
|
if (config('app.env') !== 'local') {
|
2021-03-21 22:51:19 +01:00
|
|
|
URL::forceScheme('https');
|
2021-03-16 15:59:03 +01:00
|
|
|
}
|
2021-09-15 14:25:12 +02:00
|
|
|
// 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();
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-04-01 11:40:12 +02:00
|
|
|
// * LOCAL FORCE eg: for Carbon
|
|
|
|
|
foreach ([\LC_TIME, \LC_MESSAGES, \LC_COLLATE, \LC_CTYPE, \LC_MONETARY] as $category) {
|
|
|
|
|
setlocale(
|
|
|
|
|
// * remove numeric to prevent float seperator to breaking numeric transactions
|
|
|
|
|
$category, \sprintf('%s_%s.UTF-8', config('app.locale'), \strtoupper(config('app.locale')))
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-09-15 14:25:12 +02:00
|
|
|
Carbon::setLocale(config('app.locale'));
|
2021-03-16 15:59:03 +01:00
|
|
|
|
2021-10-13 14:30:01 +02:00
|
|
|
// force bootstrap paginator
|
|
|
|
|
Paginator::useBootstrap();
|
|
|
|
|
|
2020-12-07 16:35:12 +01:00
|
|
|
if (!app()->runningInConsole()) {
|
2021-07-22 09:31:34 +02:00
|
|
|
try {
|
|
|
|
|
View::share('momentFiche', Moments::getCachedStar() ?? false);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Log::critical($e->getMessage());
|
|
|
|
|
View::share('momentFiche', false);
|
2021-07-22 10:23:33 +02:00
|
|
|
}
|
2021-09-16 19:31:57 +02:00
|
|
|
try {
|
|
|
|
|
View::share('ActusGlobal', Actu::getCachedActus() ?? []);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Log::critical($e->getMessage());
|
|
|
|
|
View::share('ActusGlobal', []);
|
|
|
|
|
}
|
2021-07-22 10:23:33 +02:00
|
|
|
try {
|
2021-09-16 12:04:12 +02:00
|
|
|
View::share('ArticlesGlobal', Articles::getCachedArticles() ?? []);
|
2021-07-22 10:23:33 +02:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Log::critical($e->getMessage());
|
2021-09-16 12:04:12 +02:00
|
|
|
View::share('ArticlesGlobal', []);
|
2021-07-22 09:31:34 +02:00
|
|
|
}
|
2021-09-20 23:23:46 +02:00
|
|
|
try {
|
|
|
|
|
View::share('GeneralConfigGlobal', GeneralConfig::getCachedConfigs() ?? []);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Log::critical($e->getMessage());
|
|
|
|
|
View::share('GeneralConfigGlobal', []);
|
|
|
|
|
}
|
2022-02-10 16:14:58 +01:00
|
|
|
}//end if
|
2021-09-24 00:18:02 +02:00
|
|
|
|
|
|
|
|
Blade::directive('svg', function ($arguments) {
|
|
|
|
|
// Funky madness to accept multiple arguments into the directive
|
|
|
|
|
list($path, $class) = array_pad(explode(',', trim($arguments, "() ")), 2, '');
|
2022-02-10 16:14:58 +01:00
|
|
|
$path = trim($path, "' ");
|
|
|
|
|
$class = trim($class, "' ");
|
2021-09-24 00:18:02 +02:00
|
|
|
// Create the dom document as per the other answers
|
|
|
|
|
$svg = new \DOMDocument();
|
|
|
|
|
$svg->load(public_path($path));
|
|
|
|
|
$svg->documentElement->setAttribute("class", $class);
|
|
|
|
|
$output = $svg->saveXML($svg->documentElement);
|
|
|
|
|
return $output;
|
|
|
|
|
});
|
2020-07-23 10:29:36 +02:00
|
|
|
}
|
|
|
|
|
}
|