-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResponse.php
More file actions
59 lines (48 loc) · 1.12 KB
/
Response.php
File metadata and controls
59 lines (48 loc) · 1.12 KB
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
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace Router;
use InvalidArgumentException;
use Router\Session;
class Response
{
public $route;
public $params;
public function __construct(string $route, array $params)
{
$this->route = $route;
$this->params = $params;
}
/**
* @fn getContent
*
* @return void
*/
public function getContent()
{
echo $this->render(Config::HOST . Config::ROUTES_ALLOWED[$this->route][0], $this->params);
}
/**
* @fn render
*
* @param string $path
* @return void
*/
protected function render(string $path, array $data)
{
if(file_exists($path))
{
ob_start();
switch($this->route)
{
case '401':
http_response_code(401);
break;
case '405':
http_response_code(405);
break;
}
include $path;
return ob_get_clean();
}
else throw new InvalidArgumentException('FILE NOT FOUND');
}
}