You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
4.0 KiB
92 lines
4.0 KiB
<?php
|
|
|
|
|
|
require "../vendor/autoload.php";
|
|
require "../config.php";
|
|
require "../sql/database.php";
|
|
require "../src/utils.php";
|
|
require "../src/App/react-display.php";
|
|
|
|
use IQBall\App\App;
|
|
use IQBall\App\Controller\AuthController;
|
|
use IQBall\App\Controller\EditorController;
|
|
use IQBall\App\Controller\TeamController;
|
|
use IQBall\App\Controller\UserController;
|
|
use IQBall\App\Controller\VisualizerController;
|
|
use IQBall\Core\Action;
|
|
use IQBall\Core\Connection;
|
|
use IQBall\Core\Gateway\AccountGateway;
|
|
use IQBall\Core\Gateway\TacticInfoGateway;
|
|
use IQBall\Core\Gateway\TeamGateway;
|
|
use IQBall\Core\Model\AuthModel;
|
|
use IQBall\Core\Model\TacticModel;
|
|
use IQBall\Core\Model\TeamModel;
|
|
use IQBall\Core\Session\PhpSessionHandle;
|
|
use IQBall\Core\Session\SessionHandle;
|
|
|
|
function getConnection(): Connection {
|
|
return new Connection(get_database());
|
|
}
|
|
|
|
function getUserController(): UserController {
|
|
return new UserController(new TacticModel(new TacticInfoGateway(getConnection())));
|
|
}
|
|
|
|
function getVisualizerController(): VisualizerController {
|
|
return new VisualizerController(new TacticModel(new TacticInfoGateway(getConnection())));
|
|
}
|
|
|
|
function getEditorController(): EditorController {
|
|
return new EditorController(new TacticModel(new TacticInfoGateway(getConnection())));
|
|
}
|
|
|
|
function getTeamController(): TeamController {
|
|
return new TeamController(new TeamModel(new TeamGateway(getConnection())));
|
|
}
|
|
|
|
function getAuthController(): AuthController {
|
|
return new AuthController(new AuthModel(new AccountGateway(getConnection())));
|
|
}
|
|
|
|
function getRoutes(): AltoRouter {
|
|
global $basePath;
|
|
|
|
$ar = new AltoRouter();
|
|
$ar->setBasePath($basePath);
|
|
|
|
//authentication
|
|
$ar->map("GET", "/login", Action::noAuth(fn() => getAuthController()->displayLogin()));
|
|
$ar->map("GET", "/register", Action::noAuth(fn() => getAuthController()->displayRegister()));
|
|
$ar->map("POST", "/login", Action::noAuth(fn(SessionHandle $s) => getAuthController()->confirmLogin($_POST, $s)));
|
|
$ar->map("POST", "/register", Action::noAuth(fn(SessionHandle $s) => getAuthController()->confirmRegister($_POST, $s)));
|
|
|
|
//user-related
|
|
$ar->map("GET", "/home", Action::auth(fn(SessionHandle $s) => getUserController()->home($s)));
|
|
$ar->map("GET", "/", Action::auth(fn(SessionHandle $s) => getUserController()->home($s)));
|
|
$ar->map("GET", "/settings", Action::auth(fn(SessionHandle $s) => getUserController()->settings($s)));
|
|
|
|
//tactic-related
|
|
$ar->map("GET", "/tactic/[i:id]/view", Action::auth(fn(int $id, SessionHandle $s) => getVisualizerController()->visualize($id, $s)));
|
|
$ar->map("GET", "/tactic/[i:id]/edit", Action::auth(fn(int $id, SessionHandle $s) => getEditorController()->edit($id, $s)));
|
|
$ar->map("GET", "/tactic/new", Action::auth(fn(SessionHandle $s) => getEditorController()->createNew($s)));
|
|
|
|
//team-related
|
|
$ar->map("GET", "/team/new", Action::auth(fn(SessionHandle $s) => getTeamController()->displayCreateTeam($s)));
|
|
$ar->map("POST", "/team/new", Action::auth(fn(SessionHandle $s) => getTeamController()->submitTeam($_POST, $s)));
|
|
$ar->map("GET", "/team/search", Action::auth(fn(SessionHandle $s) => getTeamController()->displayListTeamByName($s)));
|
|
$ar->map("POST", "/team/search", Action::auth(fn(SessionHandle $s) => getTeamController()->listTeamByName($_POST, $s)));
|
|
$ar->map("GET", "/team/[i:id]", Action::auth(fn(int $id, SessionHandle $s) => getTeamController()->displayTeam($id, $s)));
|
|
$ar->map("GET", "/team/members/add", Action::auth(fn(SessionHandle $s) => getTeamController()->displayAddMember($s)));
|
|
$ar->map("POST", "/team/members/add", Action::auth(fn(SessionHandle $s) => getTeamController()->addMember($_POST, $s)));
|
|
$ar->map("GET", "/team/members/remove", Action::auth(fn(SessionHandle $s) => getTeamController()->displayDeleteMember($s)));
|
|
$ar->map("POST", "/team/members/remove", Action::auth(fn(SessionHandle $s) => getTeamController()->deleteMember($_POST, $s)));
|
|
|
|
return $ar;
|
|
}
|
|
|
|
|
|
//this is a global variable
|
|
$basePath = get_public_path();
|
|
|
|
App::render(App::runMatch(getRoutes()->match(), PhpSessionHandle::init()));
|