Files
laravel-manager-packagist/src/Http/Middleware/ServeShell.php
T
2026-12-04 16:52:00 +00:00

34 lines
1.3 KiB
PHP

<?php
namespace IriksIT\Manager\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use IriksIT\Manager\Support\Names;
use IriksIT\Manager\Support\Shell;
use Symfony\Component\HttpFoundation\Response;
/**
* The screens are one page that asks the JSON routes for its data. A browser that opens a manager address gets that
* page; the page itself, and anything else that asks for JSON, gets the data. Downloads (route names `*.export`), the
* two steps of a connection with another service (`*.connect` sends the browser away, `*.callback` is where it comes back), the
* built files and the pictures of the tour are left alone.
*/
class ServeShell
{
public function handle(Request $request, Closure $next): Response
{
if (config('manager.ui') !== 'package' || ! $request->isMethodSafe() || $request->wantsJson() || $request->ajax()) {
return $next($request);
}
$name = (string) $request->route()?->getName();
if (in_array($name, [Names::route('assets'), Names::route('mascot')], true) || str_ends_with($name, '.export') || str_ends_with($name, '.connect') || str_ends_with($name, '.callback')) {
return $next($request);
}
return response()->view('manager::shell', app(Shell::class)->data($request));
}
}