106 lines
3.4 KiB
PHP
106 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Lib\Instagram\ApiFetcher;
|
|
use App\Models\Actu;
|
|
use App\Models\Articles;
|
|
use App\Models\GeneralConfig;
|
|
use App\Models\Moments;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Pagination\Paginator;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Illuminate\Support\Facades\Log;
|
|
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()
|
|
{
|
|
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
|
|
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')))
|
|
);
|
|
}
|
|
Carbon::setLocale(config('app.locale'));
|
|
|
|
// Force bootstrap paginator.
|
|
Paginator::useBootstrap();
|
|
|
|
if (!app()->runningInConsole()) {
|
|
try {
|
|
View::share('momentFiche', Moments::getCachedStar() ?? false);
|
|
} catch (\Exception $e) {
|
|
Log::critical($e->getMessage());
|
|
View::share('momentFiche', false);
|
|
}
|
|
try {
|
|
View::share('ActusGlobal', Actu::getCachedActus() ?? []);
|
|
} catch (\Exception $e) {
|
|
Log::critical($e->getMessage());
|
|
View::share('ActusGlobal', []);
|
|
}
|
|
try {
|
|
View::share('ArticlesGlobal', Articles::getCachedArticles() ?? []);
|
|
} catch (\Exception $e) {
|
|
Log::critical($e->getMessage());
|
|
View::share('ArticlesGlobal', []);
|
|
}
|
|
try {
|
|
View::share('GeneralConfigGlobal', GeneralConfig::getCachedConfigs() ?? []);
|
|
} catch (\Exception $e) {
|
|
Log::critical($e->getMessage());
|
|
View::share('GeneralConfigGlobal', []);
|
|
}
|
|
|
|
// * Instagram Singleton
|
|
App::singleton('Instagram', function () {
|
|
return new ApiFetcher();
|
|
});
|
|
}//end if
|
|
|
|
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;
|
|
});
|
|
}
|
|
}
|