1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Core\Exception; |
4: | |
5: | use Salient\Contract\Core\Exception\Exception; |
6: | use Throwable; |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | trait ExceptionTrait |
14: | { |
15: | protected ?int $ExitStatus; |
16: | |
17: | |
18: | |
19: | |
20: | public function __construct( |
21: | string $message = '', |
22: | ?Throwable $previous = null, |
23: | ?int $exitStatus = null |
24: | ) { |
25: | $this->ExitStatus = $exitStatus; |
26: | |
27: | parent::__construct($message, 0, $previous); |
28: | } |
29: | |
30: | |
31: | |
32: | |
33: | public function getExitStatus(): ?int |
34: | { |
35: | return $this->ExitStatus; |
36: | } |
37: | |
38: | |
39: | |
40: | |
41: | public function getMetadata(): array |
42: | { |
43: | return []; |
44: | } |
45: | |
46: | |
47: | |
48: | |
49: | public function __toString(): string |
50: | { |
51: | $detail = ''; |
52: | foreach ($this->getMetadata() as $key => $value) { |
53: | $detail .= sprintf("\n\n%s:\n%s", $key, rtrim((string) $value, "\r\n")); |
54: | } |
55: | return parent::__toString() . $detail; |
56: | } |
57: | } |
58: | |