diff --git a/src/Controller/FrontController.php b/src/Controller/FrontController.php index 98c5eaf..991d5c9 100644 --- a/src/Controller/FrontController.php +++ b/src/Controller/FrontController.php @@ -23,11 +23,9 @@ use Twig\Loader\FilesystemLoader; class FrontController{ private AltoRouter $router; - private Connexion $con; private array $dictControllerRole; public function __construct(string $basePath) { - $this->con = new Connexion(get_database());; $this->router = $this->createRouter($basePath); $this->dictControllerRole = [ "UserController" => "public", @@ -45,11 +43,11 @@ class FrontController{ $match = $this->router->match(); if ($match != null){ - $this->controlRoute($match); + $this->handleMatch($match); } else { $this->diplayViewByKind(ViewHttpResponse::twig("error.html.twig", [], HttpCodes::NOT_FOUND)); } - // $this->controlRoute($match["target"]); + // $this->handleMatch($match["target"]); // $this->handleByResponseType($this->matchRoute()); } @@ -80,13 +78,12 @@ class FrontController{ // $this->router->map("GET", "/tactic/[i:id]/edit", fn(int $id) => (new EditorController(new TacticModel(new TacticInfoGateway($this->con))))->openEditorFor($id)); } - /** - * Initialize router's settings + * Call * * @return ViewHttpResponse */ - private function controlRoute($match){ + private function handleMatch($match){ $tag = $match['target']; $action = $this->getAction($match); @@ -112,13 +109,25 @@ class FrontController{ } } - private function getAction($match) : string { + /** + * Get the right method to call to do an action + * + * @param array $match + * @return string + */ + private function getAction(array $match) : string { if (isset($match["params"]["action"])){ return $match["params"]["action"]; } return "home"; } + /** + * Initialize the right controller by the user's role + * + * @param string $controller + * @return void + */ private function initControllerByRole(string $controller) { $index = $controller; @@ -132,7 +141,7 @@ class FrontController{ return $controller; } } - // A décommenter quand méthode de connexion disponible + // A décommenter/remplacer quand méthode de connexion disponible // $connected = (new UserController())->login($this->dictControllerRole[$controller]); // if (!$connected){ @@ -146,7 +155,7 @@ class FrontController{ } /** - * Redirect the return of the response by the response's type + * Redirect the return by the response's type * * @param array $match * @return void