1 | <?php |
||
2 | /** |
||
3 | * |
||
4 | */ |
||
5 | |||
6 | namespace Mvc5\Exception; |
||
7 | |||
8 | use function http_response_code; |
||
9 | use function ini_get; |
||
10 | use function in_array; |
||
11 | use function ob_end_clean; |
||
12 | use function ob_get_level; |
||
13 | use function php_sapi_name; |
||
14 | |||
15 | class ErrorException |
||
16 | extends \ErrorException |
||
17 | implements Throwable |
||
18 | { |
||
19 | /** |
||
20 | * |
||
21 | */ |
||
22 | use Exception; |
||
23 | |||
24 | /** |
||
25 | * @param int $severity |
||
26 | * @param string $message |
||
27 | * @param string $file |
||
28 | * @param int $line |
||
29 | * @return bool |
||
30 | * @codeCoverageIgnore |
||
31 | */ |
||
32 | static function handler(int $severity, string $message, string $file, int $line) |
||
33 | { |
||
34 | if (!ini_get('display_errors') || |
||
35 | in_array($severity, [E_DEPRECATED, E_USER_DEPRECATED]) || 'cli' === php_sapi_name()) { |
||
36 | return false; |
||
37 | } |
||
38 | |||
39 | $success = true; |
||
40 | while(ob_get_level() && $success) { |
||
41 | $success = ob_end_clean(); |
||
42 | } |
||
43 | |||
44 | http_response_code(500); |
||
45 | |||
46 | $exception = new self($message, 0, $severity, $file, $line); |
||
47 | |||
48 | include __DIR__ . '/../../view/exception.phtml'; |
||
49 | |||
50 | exit(70); |
||
0 ignored issues
–
show
|
|||
51 | } |
||
52 | } |
||
53 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.