<?php

use Acms\Services\Setup\Detector;
use Acms\Services\Setup\Http\Middleware\InstalledGuardMiddleware;
use Acms\Services\Setup\Http\Middleware\SessionMiddleware;
use Acms\Services\Setup\Http\Pipeline;
use Acms\Services\Setup\Http\Request;
use Acms\Services\Setup\InstallStatus;
use Acms\Services\Setup\SetupSession;

require_once(dirname(__FILE__) . '/application.php');

// メンテナンスメニュー。未インストールなら install.php へ誘導（REQUIRE_INSTALLED）。
// ログイン画面/認証は Action（Detector）側で分岐するため AuthMiddleware は通さない。
$session = new SetupSession();
$pipeline = new Pipeline(
    [
        new SessionMiddleware($session),
        new InstalledGuardMiddleware(new InstallStatus(), InstalledGuardMiddleware::REQUIRE_INSTALLED),
    ],
    new Detector($session)
);
$pipeline->handle(Request::fromGlobals())->emit();

App::checkException();
