|
|
@ -23,11 +23,9 @@ use Twig\Loader\FilesystemLoader;
|
|
|
|
class FrontController{
|
|
|
|
class FrontController{
|
|
|
|
|
|
|
|
|
|
|
|
private AltoRouter $router;
|
|
|
|
private AltoRouter $router;
|
|
|
|
private Connexion $con;
|
|
|
|
|
|
|
|
private array $dictControllerRole;
|
|
|
|
private array $dictControllerRole;
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct(string $basePath) {
|
|
|
|
public function __construct(string $basePath) {
|
|
|
|
$this->con = new Connexion(get_database());;
|
|
|
|
|
|
|
|
$this->router = $this->createRouter($basePath);
|
|
|
|
$this->router = $this->createRouter($basePath);
|
|
|
|
$this->dictControllerRole = [
|
|
|
|
$this->dictControllerRole = [
|
|
|
|
"UserController" => "public",
|
|
|
|
"UserController" => "public",
|
|
|
@ -45,11 +43,11 @@ class FrontController{
|
|
|
|
|
|
|
|
|
|
|
|
$match = $this->router->match();
|
|
|
|
$match = $this->router->match();
|
|
|
|
if ($match != null){
|
|
|
|
if ($match != null){
|
|
|
|
$this->controlRoute($match);
|
|
|
|
$this->handleMatch($match);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$this->diplayViewByKind(ViewHttpResponse::twig("error.html.twig", [], HttpCodes::NOT_FOUND));
|
|
|
|
$this->diplayViewByKind(ViewHttpResponse::twig("error.html.twig", [], HttpCodes::NOT_FOUND));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// $this->controlRoute($match["target"]);
|
|
|
|
// $this->handleMatch($match["target"]);
|
|
|
|
// $this->handleByResponseType($this->matchRoute());
|
|
|
|
// $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));
|
|
|
|
// $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
|
|
|
|
* @return ViewHttpResponse
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function controlRoute($match){
|
|
|
|
private function handleMatch($match){
|
|
|
|
$tag = $match['target'];
|
|
|
|
$tag = $match['target'];
|
|
|
|
|
|
|
|
|
|
|
|
$action = $this->getAction($match);
|
|
|
|
$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"])){
|
|
|
|
if (isset($match["params"]["action"])){
|
|
|
|
return $match["params"]["action"];
|
|
|
|
return $match["params"]["action"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "home";
|
|
|
|
return "home";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Initialize the right controller by the user's role
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param string $controller
|
|
|
|
|
|
|
|
* @return void
|
|
|
|
|
|
|
|
*/
|
|
|
|
private function initControllerByRole(string $controller) {
|
|
|
|
private function initControllerByRole(string $controller) {
|
|
|
|
|
|
|
|
|
|
|
|
$index = $controller;
|
|
|
|
$index = $controller;
|
|
|
@ -132,7 +141,7 @@ class FrontController{
|
|
|
|
return $controller;
|
|
|
|
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]);
|
|
|
|
// $connected = (new UserController())->login($this->dictControllerRole[$controller]);
|
|
|
|
// if (!$connected){
|
|
|
|
// 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
|
|
|
|
* @param array $match
|
|
|
|
* @return void
|
|
|
|
* @return void
|
|
|
|