32 lines
1.0 KiB
PHP
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);
|
|
}
|
|
}
|