Files

37 lines
1.0 KiB
PHP
Raw Permalink Normal View History

2026-10-12 07:47:42 -04:00
<?php
declare(strict_types=1);
namespace Pterodactyl\Services\Themes;
use Illuminate\Support\Facades\File;
use Pterodactyl\Services\Extensions\ExtensionManifest;
/**
* The `dist/theme.json` defineThemeConfig writes beside a theme's build.
*/
final readonly class ThemeBuild
{
/**
2026-10-12 21:24:43 -04:00
* @param list<string> $parents the themes this one extends whose stylesheets its stylesheet was built over
2026-10-12 07:47:42 -04:00
*/
2026-10-12 19:13:11 -04:00
public function __construct(
2026-10-12 21:24:43 -04:00
public array $parents = [],
2026-10-12 19:13:11 -04:00
) {}
2026-10-12 07:47:42 -04:00
public static function of(ExtensionManifest $theme): self
{
$path = $theme->path(...explode('/', ThemeDefinition::BUILD_INFO));
$data = is_file($path) ? rescue(fn (): mixed => json_decode(File::get($path), true, 8, JSON_THROW_ON_ERROR), report: false) : null;
if (! is_array($data)) {
return new self;
}
2026-10-12 19:13:11 -04:00
$parents = $data['parents'] ?? null;
2026-10-12 07:47:42 -04:00
return new self(
2026-10-12 21:24:43 -04:00
parents: is_array($parents) ? array_values(array_filter($parents, is_string(...))) : [],
2026-10-12 07:47:42 -04:00
);
}
}