<commit_before><?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use Aura\Sql\ExtendedPdo;
use Aura\SqlQuery\QueryFactory;

set_include_path(get_include_path() . PATH_SEPARATOR . "../classes/");
spl_autoload_register();
require "../vendor/autoload.php";

function redirect(Response $response, int $code, string $location) {
    $response = $response->withStatus($code);
    $response = $response->withHeader("Location", $location);
    return $response;
}

date_default_timezone_set("Asia/Taipei");

$config["displayErrorDetails"] = true;

$app = new \Slim\App(["settings" => $config]);
$container = $app->getContainer();
$container["view"] = function ($container) {
    $view = new \Slim\Views\Twig("../templates", [
    ]);
    $basePath = rtrim(str_ireplace("index.php", "", $container["request"]->getUri()->getBasePath()), "/");
    $view->addExtension(new Slim\Views\TwigExtension($container["router"], $basePath));
    $view->getEnvironment()->addFilter(new Twig_Filter('markdown', function($string) {
        return Parsedown::instance()->setMarkupEscaped(true)->text($string);
    }, array("is_safe" => array("html"))));
    $view["login"] = $container->session["login"] ?? 0;
    $view["messages"] = $container->messages;
    return $view;
};
$container["db"] = function ($container) {
    return new ExtendedPdo("pgsql:dbname=toyoj user=toyojweb");
};
$container["qf"] = function ($container) {
    return new QueryFactory("pgsql");
};
$container["errorview"] = function ($container) {
    return function (Response $response, int $status, string $message) use ($container) {
        $response = $response->withStatus($status);
        return $container->view->render($response, "error.html", array("status" => $status, "message" => $message));
    };
};
$container["notFoundHandler"] = function ($container) {
    return function (Request $request, Response $response) use ($container) {
        return ($container->errorview)($response, 404, "Not Found");
    };
};
$container["session"] = function ($container) {
    return new \Toyoj\SessionWrapper();
};
$container["messages"] = function ($container) {
    return new \Toyoj\MessageWrapper($container->session);
};
$container["forms"] = function ($container) {
    return new \Toyoj\FormValidator();
};

$app->get("/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Index::get($this, $request, $response);
})->setName("index");

$app->get("/login", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Account::showLoginPage($this, $request, $response);
})->setName("login");
$app->post("/login", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Account::login($this, $request, $response);
});

$app->get("/logout", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Account::showLogoutPage($this, $request, $response);
})->setName("logout");
$app->post("/logout", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Account::logout($this, $request, $response);
});

$app->get("/signup", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Account::showSignupPage($this, $request, $response);
})->setName("signup");
$app->post("/signup", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Account::signup($this, $request, $response);
});

$app->get("/problems/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Problem::showAll($this, $request, $response);
})->setName("problem-list");

$app->get("/problems/new", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Problem::showCreatePage($this, $request, $response);
})->setName("problem-new");
$app->post("/problems/new", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Problem::create($this, $request, $response);
});

$app->get("/problems/{pid:[0-9]+}/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Problem::show($this, $request, $response);
})->setName("problem");
$app->post("/problems/{pid:[0-9]+}/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Problem::submit($this, $request, $response);
});

$app->get("/problems/{pid:[0-9]+}/edit", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Problem::showEditPage($this, $request, $response);
})->setName("problem-edit");
$app->post("/problems/{pid:[0-9]+}/edit", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Problem::edit($this, $request, $response);
});

$app->get("/problems/{pid:[0-9]+}/subtasks/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Subtask::showAll($this, $request, $response);
})->setName("subtask-list");

$app->get("/problems/{pid:[0-9]+}/subtasks/new", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Subtask::showCreatePage($this, $request, $response);
})->setName("subtask-new");
$app->post("/problems/{pid:[0-9]+}/subtasks/new", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Subtask::create($this, $request, $response);
});

$app->get("/problems/{pid:[0-9]+}/subtasks/{subtaskid:[0-9]+}/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Subtask::show($this, $request, $response);
})->setName("subtask");

$app->get("/problems/{pid:[0-9]+}/subtasks/{subtaskid:[0-9]+}/edit", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Subtask::showEditPage($this, $request, $response);
})->setName("subtask-edit");
$app->post("/problems/{pid:[0-9]+}/subtasks/{subtaskid:[0-9]+}/edit", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Subtask::editOrDelete($this, $request, $response);
});

$app->get("/problems/{pid:[0-9]+}/tests/", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\TestCase::showAll($this, $request, $response);
});

$app->get("/problems/{pid:[0-9]+}/tests/new", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\TestCase::showCreatePage($this, $request, $response);
})->setName("test-new");
$app->post("/problems/{pid:[0-9]+}/tests/new", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\TestCase::create($this, $request, $response);
});

$app->get("/problems/{pid:[0-9]+}/tests/{testid:[0-9]+}/", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\TestCase::show($this, $request, $response);
})->setName("test");

$app->get("/problems/{pid:[0-9]+}/tests/{testid:[0-9]+}/edit", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\TestCase::showEditPage($this, $request, $response);
})->setName("test-edit");
$app->post("/problems/{pid:[0-9]+}/tests/{testid:[0-9]+}/edit", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\TestCase::edit($this, $request, $response);
});

$app->get("/submissions/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Submission::showAll($this, $request, $response);
})->setName("submission-list");

$app->get("/submissions/{sid:[0-9]+}/", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\Submission::show($this, $request, $response);
})->setName("submission");

$app->get("/users/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\User::showAll($this, $request, $response);
})->setName("user-list");

$app->get("/users/{uid:[0-9]+}/", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\User::show($this, $request, $response);
})->setName("user");

$app->run();
<commit_msg>Remove the unused \redirect.<commit_after><?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
use Aura\Sql\ExtendedPdo;
use Aura\SqlQuery\QueryFactory;

set_include_path(get_include_path() . PATH_SEPARATOR . "../classes/");
spl_autoload_register();
require "../vendor/autoload.php";

date_default_timezone_set("Asia/Taipei");

$config["displayErrorDetails"] = true;

$app = new \Slim\App(["settings" => $config]);
$container = $app->getContainer();
$container["view"] = function ($container) {
    $view = new \Slim\Views\Twig("../templates", [
    ]);
    $basePath = rtrim(str_ireplace("index.php", "", $container["request"]->getUri()->getBasePath()), "/");
    $view->addExtension(new Slim\Views\TwigExtension($container["router"], $basePath));
    $view->getEnvironment()->addFilter(new Twig_Filter('markdown', function($string) {
        return Parsedown::instance()->setMarkupEscaped(true)->text($string);
    }, array("is_safe" => array("html"))));
    $view["login"] = $container->session["login"] ?? 0;
    $view["messages"] = $container->messages;
    return $view;
};
$container["db"] = function ($container) {
    return new ExtendedPdo("pgsql:dbname=toyoj user=toyojweb");
};
$container["qf"] = function ($container) {
    return new QueryFactory("pgsql");
};
$container["errorview"] = function ($container) {
    return function (Response $response, int $status, string $message) use ($container) {
        $response = $response->withStatus($status);
        return $container->view->render($response, "error.html", array("status" => $status, "message" => $message));
    };
};
$container["notFoundHandler"] = function ($container) {
    return function (Request $request, Response $response) use ($container) {
        return ($container->errorview)($response, 404, "Not Found");
    };
};
$container["session"] = function ($container) {
    return new \Toyoj\SessionWrapper();
};
$container["messages"] = function ($container) {
    return new \Toyoj\MessageWrapper($container->session);
};
$container["forms"] = function ($container) {
    return new \Toyoj\FormValidator();
};

$app->get("/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Index::get($this, $request, $response);
})->setName("index");

$app->get("/login", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Account::showLoginPage($this, $request, $response);
})->setName("login");
$app->post("/login", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Account::login($this, $request, $response);
});

$app->get("/logout", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Account::showLogoutPage($this, $request, $response);
})->setName("logout");
$app->post("/logout", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Account::logout($this, $request, $response);
});

$app->get("/signup", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Account::showSignupPage($this, $request, $response);
})->setName("signup");
$app->post("/signup", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Account::signup($this, $request, $response);
});

$app->get("/problems/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Problem::showAll($this, $request, $response);
})->setName("problem-list");

$app->get("/problems/new", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Problem::showCreatePage($this, $request, $response);
})->setName("problem-new");
$app->post("/problems/new", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Problem::create($this, $request, $response);
});

$app->get("/problems/{pid:[0-9]+}/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Problem::show($this, $request, $response);
})->setName("problem");
$app->post("/problems/{pid:[0-9]+}/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Problem::submit($this, $request, $response);
});

$app->get("/problems/{pid:[0-9]+}/edit", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Problem::showEditPage($this, $request, $response);
})->setName("problem-edit");
$app->post("/problems/{pid:[0-9]+}/edit", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Problem::edit($this, $request, $response);
});

$app->get("/problems/{pid:[0-9]+}/subtasks/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Subtask::showAll($this, $request, $response);
})->setName("subtask-list");

$app->get("/problems/{pid:[0-9]+}/subtasks/new", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Subtask::showCreatePage($this, $request, $response);
})->setName("subtask-new");
$app->post("/problems/{pid:[0-9]+}/subtasks/new", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Subtask::create($this, $request, $response);
});

$app->get("/problems/{pid:[0-9]+}/subtasks/{subtaskid:[0-9]+}/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Subtask::show($this, $request, $response);
})->setName("subtask");

$app->get("/problems/{pid:[0-9]+}/subtasks/{subtaskid:[0-9]+}/edit", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Subtask::showEditPage($this, $request, $response);
})->setName("subtask-edit");
$app->post("/problems/{pid:[0-9]+}/subtasks/{subtaskid:[0-9]+}/edit", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Subtask::editOrDelete($this, $request, $response);
});

$app->get("/problems/{pid:[0-9]+}/tests/", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\TestCase::showAll($this, $request, $response);
});

$app->get("/problems/{pid:[0-9]+}/tests/new", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\TestCase::showCreatePage($this, $request, $response);
})->setName("test-new");
$app->post("/problems/{pid:[0-9]+}/tests/new", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\TestCase::create($this, $request, $response);
});

$app->get("/problems/{pid:[0-9]+}/tests/{testid:[0-9]+}/", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\TestCase::show($this, $request, $response);
})->setName("test");

$app->get("/problems/{pid:[0-9]+}/tests/{testid:[0-9]+}/edit", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\TestCase::showEditPage($this, $request, $response);
})->setName("test-edit");
$app->post("/problems/{pid:[0-9]+}/tests/{testid:[0-9]+}/edit", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\TestCase::edit($this, $request, $response);
});

$app->get("/submissions/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\Submission::showAll($this, $request, $response);
})->setName("submission-list");

$app->get("/submissions/{sid:[0-9]+}/", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\Submission::show($this, $request, $response);
})->setName("submission");

$app->get("/users/", function (Request $request, Response $response) {
    return \Toyoj\Controllers\User::showAll($this, $request, $response);
})->setName("user-list");

$app->get("/users/{uid:[0-9]+}/", function (Request $request, Response $response, array $args) {
    return \Toyoj\Controllers\User::show($this, $request, $response);
})->setName("user");

$app->run();

{'fraction_non_alphanumeric': 0.2158983115158414, 'fraction_numerical': 0.0065768671346360585, 'mean_word_length': 5.945103205972771, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 143, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7208769', 'n_tokens_mistral': 5134, 'n_tokens_neox': 5061, 'n_words': 935}