front-controller #17
Merged
maxime.batista
merged 12 commits from front-controller
into salva
1 year ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'front-controller'
Deleting a branch is permanent. It CANNOT be undone. Continue?
I did the FRONT CONTROLLERRRRR. (Salva version lol)
When you create a new controller
When you create a new controller, define the path to call it here (image 1).
Don't forget to associate a controller with a role.
The action's main method
The main method have to return a
ViewHttpResponse
.If you create a new action, please make sure that the action's main method have the same name than the action (image 2 and 3) and to make the main method public.
* @return void
*/
public function run() : void {
$this->initializeRouterMap();
move this call in the constructor, or better, inline its content in the
createRouter
method.} else {
$this->diplayViewByKind(ViewHttpResponse::twig("error.html.twig", [], HttpCodes::NOT_FOUND));
}
// $this->handleMatch($match["target"]);
remove comments
$this->router->map("GET", "/", "UserController");
$this->router->map("GET", "/[a:action]?", "UserController");
$this->router->map("GET", "/tactic/[a:action]/[i:idTactic]?", "EditorController");
// $this->router->map("GET", "/tactic/[i:id]/edit", "EditorController");
remove those comments
}
/**
* Call
call what
}
// private function sanitizeParam($params) {
// foreach ($key, $value : )
remove those comments
// foreach ($key, $value : )
// }
private function tryToCall($controller, $action, array $params){
explicitly set its return type to
HttpResponse
unset($params["action"]);
$controller = $this->initControllerByRole($controller);
try {
if (is_callable(array($controller, $action))){
}
}
// A décommenter/remplacer quand méthode de connexion disponible
you can inline those two lines
// return "null";
// }
$_SESSION['role'] = 'public'; // Remplacer par appel de la méthode de connexion
useless here, don't try to anticipate future code
}
/**
* Redirect the return by the response's type
* @return void
*/
private function handleResponseByType(HttpResponse $response) : void {
// $response = call_user_func_array($match['target'], $match['params']);
http_response_code($response->getCode());
if ($response instanceof ViewHttpResponse) {
$this->diplayViewByKind($response);
remove this comment
$file = $response->getFile();
$args = $response->getArguments();
switch ($response->getViewKind()) {
typo here in
display
meant to request changes*
./format.sh
and./verify.sh
scriptsdc4c95026c
to81439e341d
1 year ago81439e341d
to0a4ef19436
1 year ago5d4bb84368
into salva 1 year agoReviewers
5d4bb84368
.