Files
laralog/app/Support/helpers.php
T
ak 7364def979 fix: theme('asset', path, name) 忽略指定主题的 bug
theme() 辅助函数 asset 分支只传了路径,丢弃第二个参数(主题名),导致主题管理页所有卡片都显示激活主题的截图。修复透传,并补回归测试
2026-08-12 04:05:25 +08:00

45 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
use App\Blog\Support\ThemeManager;
if (! function_exists('theme_view')) {
/**
* 渲染主题视图:激活主题目录已前置到全局视图路径,主题缺失时自动回退默认视图。
*/
function theme_view(string $view, array $data = []): \Illuminate\Contracts\View\View
{
return view($view, $data);
}
}
if (! function_exists('theme')) {
/**
* 主题辅助函数:theme() / theme('asset', 'style.css') / theme('var', 'key', default)
*/
function theme(?string $method = null, ...$args): mixed
{
$manager = app(ThemeManager::class);
return match ($method) {
'asset' => $manager->assetUrl($args[0] ?? '', $args[1] ?? null),
'var' => $manager->variable($args[0] ?? '', $args[1] ?? null),
'vars' => $manager->variables(),
'name' => $manager->active(),
default => $manager,
};
}
}
if (! function_exists('blog_setting')) {
/**
* 读取博客设置(Setting 表,带缓存)。
*/
function blog_setting(string $key, mixed $default = null): mixed
{
return \App\Models\Setting::get($key, $default);
}
}