ldc-gen-game-web/app/Http/Middleware/CheckGameStatus.php

42 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2026-10-02 12:09:46 +02:00
declare(strict_types=1);
namespace App\Http\Middleware;
use App\Models\Settings;
2026-10-02 12:09:46 +02:00
use Closure;
use Illuminate\Http\Request;
2026-10-02 12:09:46 +02:00
use RuntimeException;
class CheckGameStatus
{
/**
* Handle an incoming request.
*
* * Check with game settings which page should be shown and redirect if needed.
*
* @return mixed
2026-10-02 12:09:46 +02:00
*
* @throws RuntimeException If tha game has an unhandled state.
*/
2026-10-02 12:09:46 +02:00
public function handle(Request $request, Closure $next)
{
2026-10-02 12:09:46 +02:00
/** @var Settings $settings */
$settings = resolve(Settings::class);
return match (true) {
// * End page
2026-10-02 12:09:46 +02:00
$settings->should_display_end_page => to_route('fo.end'),
// * Teaser
2026-10-02 12:09:46 +02:00
$settings->should_display_teaser_page => to_route('fo.teaser'),
// * Game is ended
$settings->game_has_ended => redirect($settings->redirect_close),
// * Game has started
$settings->game_has_begun => $next($request),
// * The game will begun, but has no teaser activated.
default => redirect($settings->redirect_close)
};
}
}