Total Complexity | 8 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
11 | class HttpException extends Exception { |
||
12 | |||
13 | private static $controller = 'errors'; |
||
14 | |||
15 | /** |
||
16 | * @param int $code |
||
17 | * @param string $message |
||
18 | */ |
||
19 | public function __construct($code, $message = '') { |
||
21 | } |
||
22 | |||
23 | /** Executa uma resposta HTTP de erro */ |
||
24 | public function run() { |
||
25 | $app = Application::app(); |
||
26 | $app->setPage($this->code); |
||
27 | $app->view = new View($this->code, ['exception' => $this]); |
||
28 | $controller = ControllerFactory::create(static::$controller, '_' . $this->code); |
||
|
|||
29 | |||
30 | if (get_class($controller) !== get_class($app->controller)) { |
||
31 | $app->controller = $controller; |
||
32 | } |
||
33 | //var_dump('response error: ' . $this->code); |
||
34 | http_response_code($this->code); |
||
35 | $this->retry(); |
||
36 | } |
||
37 | |||
38 | /** Define 404 caso definiu um erro inválido */ |
||
39 | protected function retry() { |
||
40 | try { |
||
41 | Application::app()->run(); |
||
42 | } catch (HttpException $e) { |
||
43 | if (!$this->is404()) { |
||
44 | $e->run(); |
||
45 | } |
||
46 | } |
||
47 | } |
||
48 | |||
49 | private function is404() { |
||
51 | } |
||
52 | |||
53 | /** @return boolean */ |
||
54 | public static function isErrorCode($code) { |
||
59 |