diff --git a/Documentation/php.puml b/Documentation/php.puml new file mode 100644 index 0000000..8641900 --- /dev/null +++ b/Documentation/php.puml @@ -0,0 +1,8 @@ +@startuml + +class FrontController { + - router : AltoRouter + +} + +@enduml \ No newline at end of file diff --git a/public/index.php b/public/index.php index 4c5290b..d1fee44 100644 --- a/public/index.php +++ b/public/index.php @@ -34,19 +34,12 @@ $con = new Connexion(get_database()); $router = new AltoRouter(); $router->setBasePath($basePath); -$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig); -$router->map("GET", "/", fn() => $sampleFormController->displayForm()); -$router->map("POST", "/submit", fn() => $sampleFormController->submitForm($_POST)); -$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); -} +$frontController = new FrontController($router); + +//$sampleFormController = new SampleFormController(new FormResultGateway($con), $twig); + + + + + -call_user_func($match['target']); diff --git a/src/Controller/FrontController.php b/src/Controller/FrontController.php new file mode 100644 index 0000000..dcee0b1 --- /dev/null +++ b/src/Controller/FrontController.php @@ -0,0 +1,39 @@ +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']); + } + + +} \ No newline at end of file diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php new file mode 100644 index 0000000..e69de29