1
|
|
|
<?php |
2
|
|
|
namespace Yiisoft\Yii\Web\ErrorHandler; |
3
|
|
|
|
4
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
5
|
|
|
|
6
|
|
|
abstract class ThrowableRenderer implements ThrowableRendererInterface |
7
|
|
|
{ |
8
|
|
|
private const SEVERITY_NAMES = [ |
9
|
|
|
E_COMPILE_ERROR => 'PHP Compile Error', |
10
|
|
|
E_COMPILE_WARNING => 'PHP Compile Warning', |
11
|
|
|
E_CORE_ERROR => 'PHP Core Error', |
12
|
|
|
E_CORE_WARNING => 'PHP Core Warning', |
13
|
|
|
E_DEPRECATED => 'PHP Deprecated Warning', |
14
|
|
|
E_ERROR => 'PHP Fatal Error', |
15
|
|
|
E_NOTICE => 'PHP Notice', |
16
|
|
|
E_PARSE => 'PHP Parse Error', |
17
|
|
|
E_RECOVERABLE_ERROR => 'PHP Recoverable Error', |
18
|
|
|
E_STRICT => 'PHP Strict Warning', |
19
|
|
|
E_USER_DEPRECATED => 'PHP User Deprecated Warning', |
20
|
|
|
E_USER_ERROR => 'PHP User Error', |
21
|
|
|
E_USER_NOTICE => 'PHP User Notice', |
22
|
|
|
E_USER_WARNING => 'PHP User Warning', |
23
|
|
|
E_WARNING => 'PHP Warning', |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var ServerRequestInterface |
28
|
|
|
*/ |
29
|
|
|
protected $request; |
30
|
|
|
|
31
|
|
|
protected function getThrowableName(\Throwable $t) |
32
|
|
|
{ |
33
|
|
|
$name = get_class($t); |
34
|
|
|
|
35
|
|
|
if ($t instanceof \ErrorException && isset(self::SEVERITY_NAMES[$t->getSeverity()])) { |
36
|
|
|
$name .= ' (' . self::SEVERITY_NAMES[$t->getSeverity()] . ')'; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return $name; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function convertThrowableToVerboseString(\Throwable $t): string |
43
|
|
|
{ |
44
|
|
|
$message = $this->getThrowableName($t) . "with message '{$t->getMessage()}' \n\nin " |
45
|
|
|
. $t->getFile() . ':' . $t->getLine() . "\n\n" |
46
|
|
|
. "Stack trace:\n" . $t->getTraceAsString(); |
47
|
|
|
return $message; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function setRequest(ServerRequestInterface $request): void |
51
|
|
|
{ |
52
|
|
|
$this->request = $request; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|