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.
Application-Web/public/index.php

100 lines
4.0 KiB

<?php
require "../vendor/autoload.php";
require "../config.php";
require "../sql/database.php";
require "utils.php";
require "../src/react-display.php";
use App\Controller\AuthController;
use App\Controller\EditorController;
use App\Controller\Route\Action;
use App\Controller\Route\FrontController;
use App\Controller\TeamController;
use App\Controller\UserController;
use App\Controller\VisualizerController;
use App\Gateway\AccountGateway;
use App\Gateway\TacticInfoGateway;
use App\Gateway\TeamGateway;
use App\Model\AuthModel;
use App\Model\TacticModel;
use App\Model\TeamModel;
use App\Session\MutableSessionHandle;
use App\Session\PhpSessionHandle;
use App\Connexion;
use App\Session\SessionHandle;
$connexion = new Connexion(get_database());
function getUserController(): UserController {
global $connexion;
return new UserController(new TacticModel(new TacticInfoGateway($connexion)));
}
function getVisualizerController(): VisualizerController {
global $connexion;
return new VisualizerController(new TacticModel(new TacticInfoGateway($connexion)));
}
function getEditorController(): EditorController {
global $connexion;
return new EditorController(new TacticModel(new TacticInfoGateway($connexion)));
}
function getTeamController(): TeamController {
global $connexion;
return new TeamController(new TeamModel(new TeamGateway($connexion)));
}
function getAuthController(): AuthController {
global $connexion;
return new AuthController(new AuthModel(new AccountGateway($connexion)));
}
function initFrontController(FrontController $fc) {
//authentication
$fc->addRoute("GET", "/login", Action::noAuth(fn() => getAuthController()->displayLogin()));
$fc->addRoute("GET", "/register", Action::noAuth(fn() => getAuthController()->displayRegister()));
$fc->addRoute("POST", "/login", Action::noAuth(fn(SessionHandle $s) => getAuthController()->confirmLogin($_POST, $s)));
$fc->addRoute("POST", "/register", Action::noAuth(fn(SessionHandle $s) => getAuthController()->confirmRegister($_POST, $s)));
//user-related
$fc->addRoute("GET", "/home", Action::auth(fn(SessionHandle $s) => getUserController()->home($s)));
$fc->addRoute("GET", "/settings", Action::auth(fn(SessionHandle $s) => getUserController()->settings($s)));
//tactic-related
$fc->addRoute("GET", "/tactic/[i:id]/view", Action::auth(fn(int $id, SessionHandle $s) => getVisualizerController()->visualize($id, $s)));
$fc->addRoute("GET", "/tactic/[i:id]/edit", Action::auth(fn(int $id, SessionHandle $s) => getEditorController()->edit($id, $s)));
$fc->addRoute("GET", "/tactic/new", Action::auth(fn(SessionHandle $s) => getEditorController()->createNew($s)));
//team-related
$fc->addRoute("GET", "/team/new", Action::auth(fn(SessionHandle $s) => getTeamController()->displayCreateTeam($s)));
$fc->addRoute("POST", "/team/new", Action::auth(fn(SessionHandle $s) => getTeamController()->submitTeam($_POST, $s)));
$fc->addRoute("GET", "/team/search", Action::auth(fn(SessionHandle $s) => getTeamController()->displayListTeamByName($s)));
$fc->addRoute("POST", "/team/search", Action::auth(fn(SessionHandle $s) => getTeamController()->listTeamByName($_POST, $s)));
$fc->addRoute("GET", "/team/[i:id]", Action::auth(fn(int $id, SessionHandle $s) => getTeamController()->displayTeam($id, $s)));
$fc->addRoute("GET", "/team/members/add", Action::auth(fn(SessionHandle $s) => getTeamController()->displayAddMember($s)));
$fc->addRoute("POST", "/team/members/add", Action::auth(fn(SessionHandle $s) => getTeamController()->addMember($_POST, $s)));
$fc->addRoute("GET", "/team/members/remove", Action::auth(fn(SessionHandle $s) => getTeamController()->displayDeleteMember($s)));
$fc->addRoute("POST", "/team/members/remove", Action::auth(fn(SessionHandle $s) => getTeamController()->deleteMember($_POST, $s)));
}
//this is a global variable
$basePath = get_public_path();
function run() {
global $basePath;
$fc = new FrontController($basePath);
initFrontController($fc);
$fc->run(PhpSessionHandle::init());
}
run();