Add start of homepage and FrontControler (don't run it)
continuous-integration/drone/push Build is passing Details

pull/17/head
DahmaneYanis 1 year ago
parent 6aeefad564
commit 5737bd6e6b

@ -0,0 +1,8 @@
@startuml
class FrontController {
- router : AltoRouter
}
@enduml

@ -34,19 +34,12 @@ $con = new Connexion(get_database());
$router = new AltoRouter(); $router = new AltoRouter();
$router->setBasePath($basePath); $router->setBasePath($basePath);
$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig); $frontController = new FrontController($router);
$router->map("GET", "/", fn() => $sampleFormController->displayForm());
$router->map("POST", "/submit", fn() => $sampleFormController->submitForm($_POST)); //$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig);
$router->map("GET", "/twig", fn() => $sampleFormController->displayFormTwig());
$router->map("POST", "/submit-twig", fn() => $sampleFormController->submitFormTwig($_POST));
$match = $router->match();
if ($match == null) {
// TODO redirect to a 404 not found page instead (issue #1)
http_response_code(404);
echo "Page non trouvée";
exit(1);
}
call_user_func($match['target']);

@ -0,0 +1,39 @@
<?php
class FrontController{
private AltoRouter $router;
private UserControler $userControler;
public function FrontController(AltoRouter $router){
$this->router = $router;
}
public function main() {
$this->toRoute();
}
private function toRoute(){
$this->router->map("GET", "/", fn() => $this->userControler->home());
// $this->router->map("POST", "/submit", fn() => $sampleFormController->submitForm($_POST));
// $this->router->map("GET", "/twig", fn() => $sampleFormController->displayFormTwig());
// $this->router->map("POST", "/submit-twig", fn() => $sampleFormController->submitFormTwig($_POST));
$match = $router->match();
// À remplacer par l'appel du contrôler d'erreur
if ($match == null) {
// TODO redirect to a 404 not found page instead (issue #1)
http_response_code(404);
echo "Page non trouvée";
exit(1);
}
call_user_func($match['target']);
}
}
Loading…
Cancel
Save