1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
declare(strict_types=1);
|
4
|
|
|
|
5
|
|
|
namespace Aidphp\Framework;
|
6
|
|
|
|
7
|
|
|
use Throwable;
|
8
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
9
|
|
|
|
10
|
|
|
class ErrorInfo
|
11
|
|
|
{
|
12
|
|
|
private $e;
|
13
|
|
|
private $debug;
|
14
|
|
|
private $req;
|
15
|
|
|
|
16
|
4 |
|
public function __construct(Throwable $e, bool $debug = false, ServerRequestInterface $req = null)
|
17
|
|
|
{
|
18
|
4 |
|
$this->e = $e;
|
19
|
4 |
|
$this->debug = $debug;
|
20
|
4 |
|
$this->req = $req;
|
21
|
4 |
|
}
|
22
|
|
|
|
23
|
2 |
|
public function isDebug(): bool
|
24
|
|
|
{
|
25
|
2 |
|
return $this->debug;
|
26
|
|
|
}
|
27
|
|
|
|
28
|
2 |
|
public function getUri(): string
|
29
|
|
|
{
|
30
|
2 |
|
return $this->req ? $this->req->getUri()->__toString() : ($_SERVER['REQUEST_URI'] ?? '');
|
31
|
|
|
}
|
32
|
|
|
|
33
|
2 |
|
public function getMethod(): string
|
34
|
|
|
{
|
35
|
2 |
|
return $this->req ? $this->req->getMethod() : ($_SERVER['REQUEST_METHOD'] ?? '');
|
36
|
|
|
}
|
37
|
|
|
|
38
|
1 |
|
public function getType(): string
|
39
|
|
|
{
|
40
|
1 |
|
return get_class($this->e);
|
41
|
|
|
}
|
42
|
|
|
|
43
|
1 |
|
public function getCode()
|
44
|
|
|
{
|
45
|
1 |
|
return $this->e->getCode();
|
46
|
|
|
}
|
47
|
|
|
|
48
|
1 |
|
public function getFile(): string
|
49
|
|
|
{
|
50
|
1 |
|
return $this->e->getFile();
|
51
|
|
|
}
|
52
|
|
|
|
53
|
1 |
|
public function getLine(): int
|
54
|
|
|
{
|
55
|
1 |
|
return $this->e->getLine();
|
56
|
|
|
}
|
57
|
|
|
|
58
|
1 |
|
public function getMessage(): string
|
59
|
|
|
{
|
60
|
1 |
|
return $this->e->getMessage();
|
61
|
|
|
}
|
62
|
|
|
|
63
|
1 |
|
public function getTrace(): array
|
64
|
|
|
{
|
65
|
1 |
|
return $this->e->getTrace();
|
66
|
|
|
}
|
67
|
|
|
|
68
|
2 |
|
public function getParameters(): array
|
69
|
|
|
{
|
70
|
2 |
|
return $this->req ? [
|
71
|
1 |
|
'GET' => $this->req->getQueryParams(),
|
72
|
1 |
|
'POST' => $this->req->getParsedBody(),
|
73
|
1 |
|
'COOKIES' => $this->req->getCookieParams(),
|
74
|
1 |
|
'FILES' => $this->req->getUploadedFiles(),
|
75
|
1 |
|
'SERVER' => $this->req->getServerParams(),
|
76
|
1 |
|
'PARAMS' => $this->req->getAttributes(),
|
77
|
|
|
] : [
|
78
|
2 |
|
'GET' => $_GET,
|
79
|
1 |
|
'POST' => $_POST,
|
80
|
1 |
|
'COOKIES' => $_COOKIE,
|
81
|
1 |
|
'FILES' => $_FILES,
|
82
|
1 |
|
'SERVER' => $_SERVER,
|
83
|
|
|
'PARAMS' => [],
|
84
|
|
|
];
|
85
|
|
|
}
|
86
|
|
|
} |