<?php

use Acms\Services\Setup\Http\Middleware\AuthMiddleware;
use Acms\Services\Setup\Http\Middleware\CsrfMiddleware;
use Acms\Services\Setup\Http\Middleware\SessionMiddleware;
use Acms\Services\Setup\Http\Pipeline;
use Acms\Services\Setup\Http\Request;
use Acms\Services\Setup\SetupSession;
use Acms\Services\Setup\SystemUpdate;
use Acms\Services\Setup\Tool\ToolRunner;

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

@set_time_limit(0);

// システムアップデート。認証必須・全 submit を CSRF 検証（W2。破壊的な drop も POST 経由）。
$session = new SetupSession();
$pipeline = new Pipeline(
    [
        new SessionMiddleware($session),
        new AuthMiddleware($session),
        new CsrfMiddleware($session, static fn(Request $req): bool => $req->isSubmitted()),
    ],
    new ToolRunner(new SystemUpdate(), $session)
);
$pipeline->handle(Request::fromGlobals())->emit();

App::checkException();
