ldc-gen-game-web/app/Providers/ViewServiceProvider.php

56 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2023-08-21 10:22:07 +02:00
<?php
namespace App\Providers;
use App\Models\Prize;
use App\Models\Settings;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class ViewServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
2023-12-01 11:45:12 +01:00
if (!app()->runningInConsole()) {
// * View shares
// ! Add view file pathes (also needed for console xml job).
View::addNamespace('back', resource_path('views'));
View::addNamespace('theme', resource_path('theme/mounted/views'));
2023-11-20 17:22:24 +01:00
2023-12-01 11:45:12 +01:00
$appInfos = Cache::remember('composer', 360, function () {
return json_decode(File::get(\app_path('../composer.json')));
});
// Share composer.json infos.
if (isset($appInfos->name) and isset($appInfos->version)) {
View::share('cpsr_name', $appInfos->name);
View::share('cpsr_version', $appInfos->version);
}
2023-11-23 17:31:28 +01:00
// * FORCE BOOTSTRAP PAGINATOR (or custom if in front)
// Early boot, request wont be filled as expected.
if (collect(explode('/', \request()->getPathInfo()))->get(1) === 'bo') {
Paginator::defaultView('modules.pagination');
} else {
Paginator::useBootstrapFive();
}
2023-08-21 10:22:07 +02:00
2023-12-01 15:43:00 +01:00
/** @var \App\Models\Settings */
$settings = app(Settings::class);
2023-08-21 10:22:07 +02:00
// On ramène le nom du jeu et le nom de la société sur toute les pages.
2023-12-01 15:43:00 +01:00
View::share('settingsGlobal', $settings);
2023-08-21 10:22:07 +02:00
// On ramène aussi tout les prix car on en a besoin sur le header.
View::share('prizesGlobal', Prize::getCached());
2023-08-21 10:22:07 +02:00
} //end if
}
}