Files
SonarDesk-Licencing-Server/modules/Stylist/Http/Middleware/ApplyActiveTheme.php
T
2026-10-20 10:19:18 +01:00

32 lines
1.0 KiB
PHP

<?php
namespace Modules\Stylist\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
use Modules\Stylist\Theme\Stylist;
use Throwable;
final class ApplyActiveTheme
{
public function handle(Request $request, Closure $next)
{
$context = $request->is('admin', 'admin/*', 'stylist', 'stylist/*') ? 'backend' : 'frontend';
try {
$theme = app(Stylist::class)->current($context);
if ($theme->type() === $context) {
$path = $theme->path().'/views';
if (is_dir($path)) {
// Prepend so ordinary view('admin.index') and @extends('layouts.app')
// resolve theme files first, then original application files.
View::getFinder()->prependLocation($path);
}
}
} catch (Throwable $exception) {
report($exception); // Original application views remain available.
}
return $next($request);
}
}