76 lines
2.6 KiB
PHP
76 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Meat;
|
|
use App\Models\Range;
|
|
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(): void
|
|
{
|
|
$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);
|
|
}
|
|
|
|
if (!app()->runningInConsole()) {
|
|
// * 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('bo.modules.pagination');
|
|
} else {
|
|
Paginator::useBootstrapFive();
|
|
}
|
|
|
|
// * Inject actual view name
|
|
View::composer('*', function ($view) {
|
|
$view->with('viewName', $view->getName());
|
|
});
|
|
|
|
// * Inject menuNodeList
|
|
View::share('menuNodeList', (function () {
|
|
/** @var \App\Models\GeneralSetting|null */
|
|
$mainMenu = app('settings')->where('type', \App\Enums\Settings\SettingsType::mainMenu)->first();
|
|
if (!$mainMenu) {
|
|
throw new \RuntimeException('Missing setting ' .
|
|
\App\Enums\Settings\SettingsType::mainMenu->label());
|
|
}
|
|
return $mainMenu->value;
|
|
})());
|
|
View::share('menuNodeDataList', app('menuNodeDataList'));
|
|
|
|
// * Inject first meat and range : needed for the bo menu.
|
|
View::share('firstMeat', (function () {
|
|
/** @var \App\Models\Meat|null */
|
|
$firstMeat = Meat::query()->first();
|
|
if (!$firstMeat) {
|
|
return null;
|
|
}
|
|
return $firstMeat;
|
|
})());
|
|
View::share('firstRange', (function () {
|
|
/** @var \App\Models\Range|null */
|
|
$firstRange = Range::query()->first();
|
|
if (!$firstRange) {
|
|
return null;
|
|
}
|
|
return $firstRange;
|
|
})());
|
|
} //end if
|
|
}
|
|
}
|