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.
85 lines
3.0 KiB
85 lines
3.0 KiB
<?php
|
|
|
|
require "../vendor/autoload.php";
|
|
require "../config.php";
|
|
require "../sql/database.php";
|
|
require "utils.php";
|
|
|
|
use App\Connexion;
|
|
use App\Controller\EditorController;
|
|
use App\Controller\SampleFormController;
|
|
use App\Gateway\FormResultGateway;
|
|
use App\Gateway\TacticInfoGateway;
|
|
use App\Http\JsonHttpResponse;
|
|
use App\Http\ViewHttpResponse;
|
|
use App\Model\TacticModel;
|
|
use Twig\Loader\FilesystemLoader;
|
|
use App\Validation\ValidationFail;
|
|
use App\Controller\ErrorController;
|
|
|
|
|
|
$loader = new FilesystemLoader('../src/Views/');
|
|
$twig = new \Twig\Environment($loader);
|
|
|
|
$basePath = get_public_path();
|
|
$con = new Connexion(get_database());
|
|
|
|
// routes initialization
|
|
$router = new AltoRouter();
|
|
$router->setBasePath($basePath);
|
|
|
|
$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig);
|
|
$editorController = new EditorController(new TacticModel(new TacticInfoGateway($con)));
|
|
|
|
|
|
$router->map("GET", "/", fn() => $sampleFormController->displayFormReact());
|
|
$router->map("POST", "/submit", fn() => $sampleFormController->submitFormReact($_POST));
|
|
$router->map("GET", "/twig", fn() => $sampleFormController->displayFormTwig());
|
|
$router->map("POST", "/submit-twig", fn() => $sampleFormController->submitFormTwig($_POST));
|
|
$router->map("GET", "/tactic/new", fn() => $editorController->makeNew());
|
|
$router->map("GET", "/tactic/[i:id]/edit", fn(int $id) => $editorController->openEditorFor($id));
|
|
|
|
$teamController = new \App\Controller\TeamController(new \App\Model\TeamModel(new \App\Gateway\TeamGateway($con)),$twig);
|
|
$router->map("GET","/team/new", fn()=>$teamController->displaySubmitTeam());
|
|
$router->map("POST","/team/new", fn()=>$teamController->SubmitTeam($_POST));
|
|
|
|
$router->map("GET","/team/list", fn()=>$teamController->displayListTeamByName());
|
|
$router->map("POST","/team/list", fn()=>$teamController->ListTeamByName($_POST));
|
|
|
|
$router->map("GET","/team/[i:id]", fn(int $id)=>$teamController->displayTeam($id));
|
|
|
|
$match = $router->match();
|
|
|
|
if ($match == null) {
|
|
http_response_code(404);
|
|
ErrorController::displayFailures([ValidationFail::notFound("Cette page n'existe pas")], $twig);
|
|
return;
|
|
}
|
|
|
|
$response = call_user_func_array($match['target'], $match['params']);
|
|
|
|
http_response_code($response->getCode());
|
|
|
|
if ($response instanceof ViewHttpResponse) {
|
|
$file = $response->getFile();
|
|
$args = $response->getArguments();
|
|
|
|
switch ($response->getViewKind()) {
|
|
case ViewHttpResponse::REACT_VIEW:
|
|
send_react_front($file, $args);
|
|
break;
|
|
case ViewHttpResponse::TWIG_VIEW:
|
|
try {
|
|
$twig->display($file, $args);
|
|
} catch (\Twig\Error\RuntimeError|\Twig\Error\SyntaxError $e) {
|
|
http_response_code(500);
|
|
echo "There was an error rendering your view, please refer to an administrator.\nlogs date: " . date("YYYD, d M Y H:i:s");
|
|
throw e;
|
|
}
|
|
break;
|
|
}
|
|
|
|
} else if ($response instanceof JsonHttpResponse) {
|
|
header('Content-type: application/json');
|
|
echo $response->getJson();
|
|
} |