commit | author | age
|
2ab29e
|
1 |
<?php |
F |
2 |
|
|
3 |
declare(strict_types= 1); |
|
4 |
|
|
5 |
namespace Framework; |
|
6 |
|
|
7 |
use ErrorException; |
4ee40e
|
8 |
use Throwable; |
2ab29e
|
9 |
|
F |
10 |
class ErrorHandler { |
|
11 |
public static function handleError( |
|
12 |
int $errno, |
|
13 |
string $errstr, |
|
14 |
string $errfile, |
|
15 |
int $errline |
|
16 |
): bool |
|
17 |
{ |
|
18 |
throw new ErrorException($errstr,0, $errno, $errfile, $errline); |
|
19 |
} |
4ee40e
|
20 |
public static function handleException(Throwable $exception) { |
F |
21 |
static $show_errors = true; |
|
22 |
|
|
23 |
if($exception instanceof Exceptions\PageNotFoundException) { |
|
24 |
http_response_code(404); |
|
25 |
$template = "404.php"; |
|
26 |
} else { |
|
27 |
http_response_code(500); |
|
28 |
$template = "500.php"; |
|
29 |
} |
|
30 |
|
|
31 |
if($show_errors) { |
|
32 |
ini_set("display_errors", "1"); |
|
33 |
}else{ |
|
34 |
ini_set("display_errors","0"); |
|
35 |
ini_set("log_errors","1"); |
|
36 |
require "views/$template"; |
|
37 |
} |
|
38 |
|
|
39 |
throw $exception; |
|
40 |
} |
2ab29e
|
41 |
} |