|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace BSP\DrWatson; |
|
5
|
|
|
|
|
6
|
|
|
use MyCLabs\Enum\Enum; |
|
7
|
|
|
use Throwable; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class DrWatson |
|
11
|
|
|
* @package BSP\DrWatson |
|
12
|
|
|
* |
|
13
|
|
|
* Add type, suspect and help to \Exception, in order to have easier times when debugging. |
|
14
|
|
|
*/ |
|
15
|
|
|
final class DrWatson extends \Exception |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var Enum |
|
19
|
|
|
* |
|
20
|
|
|
* You can use \BSP\DrWatson\ExceptionType or create your own Enum. |
|
21
|
|
|
* Please visit https://github.com/myclabs/php-enum to learn how. |
|
22
|
|
|
*/ |
|
23
|
|
|
private $type; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
* |
|
28
|
|
|
* This is a hint for developpers, should provide a fieldName, class::method, etc... |
|
29
|
|
|
* It should point out the best place to start investigation. |
|
30
|
|
|
*/ |
|
31
|
|
|
private $suspect; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var string |
|
35
|
|
|
* |
|
36
|
|
|
* This message is a hint meant for developpers, explaining reasons for the exception. It should be deeper and |
|
37
|
|
|
* more precise than \BSP\DrWatson\DrWatson::$suspect, so do not hesitate to add explanation here, even if it's |
|
38
|
|
|
* long text. |
|
39
|
|
|
* The more details there is, the easier it will be to debug. |
|
40
|
|
|
*/ |
|
41
|
|
|
private $help; |
|
42
|
|
|
|
|
43
|
1 |
|
private function __construct( |
|
44
|
|
|
Enum $exceptionType, |
|
45
|
|
|
string $message = "", |
|
46
|
|
|
string $suspect = "", |
|
47
|
|
|
string $help = "", |
|
48
|
|
|
int $code = 0, |
|
49
|
|
|
Throwable $previous = null |
|
50
|
|
|
) { |
|
51
|
1 |
|
parent::__construct($message, $code, $previous); |
|
52
|
1 |
|
$this->type = $exceptionType; |
|
53
|
1 |
|
$this->suspect = $suspect; |
|
54
|
1 |
|
$this->help = $help; |
|
55
|
1 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Named Constructor. DrWatson writes a fine report for you ! |
|
59
|
|
|
*/ |
|
60
|
1 |
|
public static function report( |
|
61
|
|
|
Enum $drWatsonExceptionType, |
|
62
|
|
|
string $message = "", |
|
63
|
|
|
string $suspect = "", |
|
64
|
|
|
string $help = "", |
|
65
|
|
|
int $code = 0, |
|
66
|
|
|
Throwable $previous = null |
|
67
|
|
|
): self { |
|
68
|
1 |
|
return new self($drWatsonExceptionType, $message, $suspect, $help, $code, $previous); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
public function type(): Enum |
|
72
|
|
|
{ |
|
73
|
1 |
|
return $this->type; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
1 |
|
public function message(): string |
|
77
|
|
|
{ |
|
78
|
1 |
|
return $this->message; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
1 |
|
public function suspect(): string |
|
82
|
|
|
{ |
|
83
|
1 |
|
return $this->suspect; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
public function help(): string |
|
87
|
|
|
{ |
|
88
|
1 |
|
return $this->help; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
1 |
|
public function code(): int |
|
92
|
|
|
{ |
|
93
|
1 |
|
return $this->code; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|