Files
pterodactyl-panel/app/Http/ViewComposers/AssetComposer.php
T

64 lines
2.0 KiB
PHP
Raw Normal View History

<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
namespace Pterodactyl\Http\ViewComposers;
2026-10-05 18:10:18 -04:00
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Services\Extensions\ExtensionHeadTags;
use Pterodactyl\Services\Extensions\ExtensionManager;
use Pterodactyl\Services\Helpers\AssetHashService;
2026-10-05 18:10:18 -04:00
use Throwable;
class AssetComposer
{
/**
* AssetComposer constructor.
*/
2026-10-05 18:10:18 -04:00
public function __construct(
private readonly AssetHashService $assetHashService,
private readonly ExtensionManager $extensionManager,
private readonly ExtensionHeadTags $extensionHeadTags,
) {}
/**
* Provide access to the asset service in the views.
*/
2022-10-14 10:59:20 -06:00
public function compose(View $view): void
{
$view->with('asset', $this->assetHashService);
2026-10-05 18:10:18 -04:00
// Rendered lazily by the layout; resolving the tags never throws.
$view->with('extensionHead', $this->extensionHeadTags);
2019-12-15 18:05:44 -08:00
$view->with('siteConfiguration', [
2026-10-05 18:10:18 -04:00
'name' => config('app.name', 'Pterodactyl'),
'locale' => config('app.locale', 'en'),
2019-12-15 18:05:44 -08:00
'recaptcha' => [
'enabled' => config('recaptcha.enabled', false),
2026-10-05 18:10:18 -04:00
'siteKey' => config('recaptcha.website_key', ''),
2019-12-15 18:05:44 -08:00
],
2026-10-05 18:10:18 -04:00
'extensions' => $this->extensionPayload(),
2019-12-15 18:05:44 -08:00
]);
}
2026-10-05 18:10:18 -04:00
/**
* The enabled frontend extensions the SPA boot loader should import, with their
* frontend settings for signed-in users and only the public ones for guests.
* Never allowed to break page rendering - worst case the SPA sees no extensions.
*
* @return array<int, array{id: string, version: string, entry: string}>
*/
private function extensionPayload(): array
{
if (! config('extensions.enabled')) {
return [];
}
try {
return $this->extensionManager->frontendPayload(authenticated: Auth::check());
} catch (Throwable) {
return [];
}
}
}