ldc-legaulois/app/Providers/AppServiceProvider.php

98 lines
3 KiB
PHP
Raw Normal View History

2020-07-23 10:29:36 +02:00
<?php
namespace App\Providers;
2021-09-16 19:31:57 +02:00
use App\Models\Actu;
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;
use Carbon\Carbon;
use Illuminate\Support\Facades\App;
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()
{
// LOCAL HTTPS FIX
if (config('app.env') !== 'local') {
2021-03-21 22:51:19 +01:00
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'));
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', []);
}
}
Blade::directive('svg', function ($arguments) {
// Funky madness to accept multiple arguments into the directive
list($path, $class) = array_pad(explode(',', trim($arguments, "() ")), 2, '');
$path = trim($path, "' ");
$class = trim($class, "' ");
// 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
}
}