41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Models\Settings;
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use RuntimeException;
|
|
|
|
class CheckGameStatus
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* * Check with game settings which page should be shown and redirect if needed.
|
|
*
|
|
* @return mixed
|
|
*
|
|
* @throws RuntimeException If tha game has an unhandled state.
|
|
*/
|
|
public function handle(Request $request, Closure $next)
|
|
{
|
|
/** @var Settings $settings */
|
|
$settings = resolve(Settings::class);
|
|
|
|
return match (true) {
|
|
// * End page
|
|
$settings->should_display_end_page => to_route('fo.end'),
|
|
// * Teaser
|
|
$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)
|
|
};
|
|
}
|
|
}
|