<?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\ImportController;
use Acms\Services\Setup\SetupSession;
use Acms\Services\Setup\Tool\ToolRunner;

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

@set_time_limit(0);

// テーマ/デモデータのインポート。認証必須・全 submit を CSRF 検証（W2）。
$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 ImportController(), $session)
);
$pipeline->handle(Request::fromGlobals())->emit();

App::checkException();
