|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace BEAR\Package\Provide\Error; |
|
6
|
|
|
|
|
7
|
|
|
use BEAR\Resource\ResourceObject; |
|
8
|
|
|
use BEAR\Sunday\Extension\Router\RouterMatch; |
|
9
|
|
|
use Throwable; |
|
10
|
|
|
|
|
11
|
|
|
use function json_encode; |
|
12
|
|
|
use function sprintf; |
|
13
|
|
|
|
|
14
|
|
|
use const JSON_PRETTY_PRINT; |
|
15
|
|
|
use const JSON_UNESCAPED_SLASHES; |
|
16
|
|
|
use const PHP_EOL; |
|
17
|
|
|
|
|
18
|
|
|
final class DevVndErrorPage extends ResourceObject |
|
19
|
|
|
{ |
|
20
|
|
|
public function __construct(Throwable $e, RouterMatch $request) |
|
21
|
|
|
{ |
|
22
|
|
|
$status = new Status($e); |
|
23
|
|
|
$this->code = $status->code; |
|
24
|
|
|
$this->headers = $this->getHeader(); |
|
|
|
|
|
|
25
|
|
|
$this->body = $this->getResponseBody($e, $request, $status); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function toString(): string |
|
29
|
|
|
{ |
|
30
|
|
|
$this->view = json_encode($this->body, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL; |
|
31
|
|
|
|
|
32
|
|
|
return $this->view; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** @return array<string, string> */ |
|
36
|
|
|
private function getHeader(): array |
|
37
|
|
|
{ |
|
38
|
|
|
return ['content-type' => 'application/vnd.error+json']; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** @return array<string, string> */ |
|
42
|
|
|
private function getResponseBody(Throwable $e, RouterMatch $request, Status $status): array |
|
43
|
|
|
{ |
|
44
|
|
|
return [ |
|
45
|
|
|
'message' => $status->text, |
|
46
|
|
|
'logref' => (string) new LogRef($e), |
|
47
|
|
|
'request' => (string) $request, |
|
48
|
|
|
'exceptions' => sprintf('%s(%s)', $e::class, $e->getMessage()), |
|
49
|
|
|
'file' => sprintf('%s(%s)', $e->getFile(), $e->getLine()), |
|
50
|
|
|
]; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..