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

54 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2023-08-21 10:22:07 +02:00
<?php
2026-10-02 12:09:46 +02:00
declare(strict_types=1);
2023-08-21 10:22:07 +02:00
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.
*/
2026-10-02 12:09:46 +02:00
public function boot(): void
2023-08-21 10:22:07 +02:00
{
2026-10-02 12:09:46 +02:00
if (! app()->runningInConsole()) {
2023-12-01 11:45:12 +01:00
// * 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
2026-10-02 12:09:46 +02:00
$appInfos = Cache::remember('composer', 84600, fn (): mixed => json_decode(File::get(\app_path('../composer.json'))));
2023-12-01 11:45:12 +01:00
// Share composer.json infos.
2026-10-02 12:09:46 +02:00
if (isset($appInfos->name, $appInfos->version)) {
2023-12-01 11:45:12 +01:00
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
2026-10-02 12:09:46 +02:00
/** @var Settings */
$settings = resolve(Settings::class);
2023-12-01 15:43:00 +01:00
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());
2026-10-02 12:09:46 +02:00
} // end if
2023-08-21 10:22:07 +02:00
}
}