| 1 | <?php |
||
| 13 | class Response |
||
| 14 | { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var array HTTP headers |
||
| 18 | */ |
||
| 19 | protected $headers = []; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var Cookie |
||
| 23 | */ |
||
| 24 | protected $cookie; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var string Output |
||
| 28 | */ |
||
| 29 | protected $output; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Response constructor. |
||
| 33 | * |
||
| 34 | * @param array $headers |
||
| 35 | * @param Cookie|null $cookie |
||
| 36 | * @param string $output |
||
| 37 | */ |
||
| 38 | 1 | public function __construct(array $headers, Cookie $cookie = null, string $output) |
|
|
|
|||
| 39 | { |
||
| 40 | 1 | $this->headers = $headers; |
|
| 41 | 1 | $this->cookie = $cookie; |
|
| 42 | 1 | $this->output = $output; |
|
| 43 | 1 | } |
|
| 44 | |||
| 45 | /** |
||
| 46 | * Get response headers as an array, to be set in the index.php file |
||
| 47 | * |
||
| 48 | * ``` |
||
| 49 | * foreach ($response->getHeaders() as $header) { |
||
| 50 | * header($header); |
||
| 51 | * } |
||
| 52 | * ``` |
||
| 53 | * |
||
| 54 | * @return array |
||
| 55 | */ |
||
| 56 | 2 | public function getHeaders(): array |
|
| 60 | |||
| 61 | /** |
||
| 62 | * Get response cookie, to be set in the index.php file |
||
| 63 | * |
||
| 64 | * ``` |
||
| 65 | * setcookie('token', $response->getCookie->getTokenString(), time() + 3600, '/', '', true, true); |
||
| 66 | * ``` |
||
| 67 | * |
||
| 68 | * @return Cookie|null |
||
| 69 | */ |
||
| 70 | 3 | public function getCookie() |
|
| 74 | |||
| 75 | /** |
||
| 76 | * Get response output, to be echoed in the index.php file |
||
| 77 | * |
||
| 78 | * ``` |
||
| 79 | * echo $response->getOutput(); |
||
| 80 | * ``` |
||
| 81 | * |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | 2 | public function getOutput(): string |
|
| 88 | } |
||
| 89 |
If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway: