progetto fatto precedentemente adattato al framework creato con il corso
filippo.bertilotti
2024-06-10 3e685fa675e58af50c45a2c1f8a3f35ff5f16ddf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
 
declare(strict_types= 1);
 
namespace Framework;
 
class Response {
    private string $body="";
 
    private array $headers = [];
 
    private int $status_code = 0;
 
    public function setStatusCode(int $code) : void {
        $this->status_code = $code;
    }
 
    public function redirect(string $url): void {
        $this->addHeader("Location: $url");
    }
 
    public function addHeader(string $header): void {
        $this->headers[] = $header;
    }
 
    public function setBody(string $body) : void {
        $this->body=$body;
    }
 
    public function getBody() : string {
        return $this->body;
    }
 
    public function send() : void {
        
        if($this->status_code) {
            http_response_code( $this->status_code );
        }
        
 
        foreach ($this->headers as $header) {
            header($header);
        }
        
        echo $this->body;
    }
 
}