1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tylercd100\LERN; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Tylercd100\LERN\Components\Notifier; |
7
|
|
|
use Tylercd100\LERN\Components\Recorder; |
8
|
|
|
use Monolog\Handler\HandlerInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The master class |
12
|
|
|
*/ |
13
|
|
|
class LERN |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var Exception |
17
|
|
|
*/ |
18
|
|
|
private $exception; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var Tylercd100\LERN\Components\Notifier |
22
|
|
|
*/ |
23
|
|
|
private $notifier; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var Tylercd100\LERN\Components\Recorder |
27
|
|
|
*/ |
28
|
|
|
private $recorder; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param Notifier|null $notifier Notifier instance |
32
|
|
|
* @param Recorder|null $recorder Recorder instance |
33
|
|
|
*/ |
34
|
21 |
|
public function __construct(Notifier $notifier = null, Recorder $recorder = null) |
35
|
|
|
{ |
36
|
21 |
|
if (empty($notifier)) { |
37
|
9 |
|
$notifier = new Notifier(); |
38
|
9 |
|
} |
39
|
21 |
|
$this->notifier = $notifier; |
|
|
|
|
40
|
|
|
|
41
|
21 |
|
if (empty($recorder)) { |
42
|
21 |
|
$recorder = new Recorder(); |
43
|
21 |
|
} |
44
|
21 |
|
$this->recorder = $recorder; |
|
|
|
|
45
|
21 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Will execute record and notify methods |
49
|
|
|
* @param Exception $e The exception to use |
50
|
|
|
* @return ExceptionModel the recorded Eloquent Model |
51
|
|
|
*/ |
52
|
3 |
|
public function handle(Exception $e) |
53
|
|
|
{ |
54
|
3 |
|
$this->exception = $e; |
55
|
3 |
|
$this->notify($e); |
56
|
3 |
|
return $this->record($e); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Stores the exception in the database |
61
|
|
|
* @param Exception $e The exception to use |
62
|
|
|
* @return Tylercd100\LERN\Models\ExceptionModel The recorded Exception as an Eloquent Model |
63
|
|
|
*/ |
64
|
3 |
|
public function record(Exception $e) |
65
|
|
|
{ |
66
|
3 |
|
$this->exception = $e; |
67
|
3 |
|
return $this->recorder->record($e); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Will send the exception to all monolog handlers |
72
|
|
|
* @param Exception $e The exception to use |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
3 |
|
public function notify(Exception $e) |
76
|
|
|
{ |
77
|
3 |
|
$this->exception = $e; |
78
|
3 |
|
$this->notifier->send($e); |
79
|
3 |
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Pushes on another Monolog Handler |
83
|
|
|
* @param HandlerInterface $handler The handler instance to add on |
84
|
|
|
* @return Notifier Returns this |
85
|
|
|
*/ |
86
|
3 |
|
public function pushHandler(HandlerInterface $handler) { |
87
|
3 |
|
$this->notifier->pushHandler($handler); |
88
|
3 |
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get Notifier |
93
|
|
|
* @return Notifier |
94
|
|
|
*/ |
95
|
3 |
|
public function getNotifier() |
96
|
|
|
{ |
97
|
3 |
|
return $this->notifier; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Set Notifier |
102
|
|
|
* @param Notifier $notifier A Notifier instance to use |
103
|
|
|
*/ |
104
|
3 |
|
public function setNotifier(Notifier $notifier) |
105
|
|
|
{ |
106
|
3 |
|
$this->notifier = $notifier; |
|
|
|
|
107
|
3 |
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get Recorder |
112
|
|
|
* @return Recorder |
113
|
|
|
*/ |
114
|
|
|
public function getRecorder() |
115
|
|
|
{ |
116
|
|
|
return $this->recorder; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Set Recorder |
121
|
|
|
* @param Recorder $recorder A Recorder instance to use |
122
|
|
|
*/ |
123
|
|
|
public function setRecorder(Recorder $recorder) |
124
|
|
|
{ |
125
|
|
|
$this->recorder = $recorder; |
|
|
|
|
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Set a string or a closure to be called that will generate the message body for the notification |
131
|
|
|
* @param function|string $cb This closure function will be passed an Exception and must return a string |
132
|
|
|
*/ |
133
|
3 |
|
public function setMessage($cb) |
134
|
|
|
{ |
135
|
3 |
|
$this->notifier->setMessage($cb); |
136
|
3 |
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Set a string or a closure to be called that will generate the subject line for the notification |
141
|
|
|
* @param function|string $cb This closure function will be passed an Exception and must return a string |
142
|
|
|
*/ |
143
|
3 |
|
public function setSubject($cb) |
144
|
|
|
{ |
145
|
3 |
|
$this->notifier->setSubject($cb); |
146
|
3 |
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
} |
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..