progetto fatto precedentemente adattato al framework creato con il corso
filippo.bertilotti
2024-06-05 15e03a88fa42f2444138ebc6f171c9a32a3a4238
commit | author | age
15e03a 1 <?php
F 2
3 declare(strict_types= 1);
4
5 namespace Framework;
6 abstract class Controller {
7     protected Request $request;
8
9     protected Response $response;
10
11     protected TemplateViewerInterface $viewer;
12
13     public function setResponse(Response $response) : void {
14         $this->response = $response;
15     }
16
17     public function setRequest(Request $request): void {
18         $this->request = $request;
19     }
20
21     public function setViewer(TemplateViewerInterface $viewer): void {
22         $this->viewer = $viewer;
23     }
24
25     protected function view(string $template, array $data = []) : Response {
26         $this->response->setBody($this->viewer->render($template, $data));
27
28         return $this->response;
29
30     }
31
32     protected function redirect(string $url): Response {
33         $this->response->redirect($url);
34         return $this->response;
35     }
36 }