1 | <?php |
||
17 | class Notifier extends Component |
||
18 | { |
||
19 | protected $config; |
||
20 | protected $log; |
||
21 | protected $messageCb; |
||
22 | protected $subjectCb; |
||
23 | protected $contextCb; |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $absolutelyDontHandle = [ |
||
29 | \Tylercd100\LERN\Exceptions\NotifierFailedException::class, |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * You can provide a Monolog Logger instance to use in the constructor |
||
34 | * @param Logger|null $log Logger instance to use |
||
35 | */ |
||
36 | 84 | public function __construct(Logger $log = null) |
|
45 | |||
46 | /** |
||
47 | * Transforms a value into a closure that returns itself when called |
||
48 | * @param callable|string $cb The value that you want to wrap in a closure |
||
49 | * @return callable |
||
50 | */ |
||
51 | 15 | private function wrapValueInClosure($cb) |
|
59 | |||
60 | /** |
||
61 | * Set a string or a closure to be called that will generate the message body for the notification |
||
62 | * @param callable|string $cb A closure or string that will be set for the message |
||
63 | * @return $this |
||
64 | */ |
||
65 | 6 | public function setMessage($cb) |
|
70 | |||
71 | /** |
||
72 | * Returns the result of the message closure |
||
73 | * @param Exception $e The Exception instance that you want to build the message around |
||
74 | * @return string The message string |
||
75 | */ |
||
76 | 36 | public function getMessage(Exception $e) |
|
90 | |||
91 | /** |
||
92 | * Gets a basic Exception message |
||
93 | * @param Exception $e The Exception instance that you want to build the message around |
||
94 | * @return String Returns the message string |
||
95 | */ |
||
96 | 3 | public function getMessageViaDefault(Exception $e) |
|
104 | |||
105 | /** |
||
106 | * Gets the Exception message using a callback if it is set |
||
107 | * @param Exception $e The Exception instance that you want to build the message around |
||
108 | * @return String|false Returns the message string or false |
||
109 | */ |
||
110 | 9 | public function getMessageViaCallback(Exception $e) |
|
117 | |||
118 | /** |
||
119 | * Gets the Exception message using a Laravel view file |
||
120 | * @param Exception $e The Exception instance that you want to build the message around |
||
121 | * @return String|false Returns the message string or false |
||
122 | */ |
||
123 | 36 | public function getMessageViaView(Exception $e) |
|
137 | |||
138 | /** |
||
139 | * Set a string or a closure to be called that will generate the subject line for the notification |
||
140 | * @param callable|string $cb A closure or string that will be set for the subject line |
||
141 | * @return $this |
||
142 | */ |
||
143 | 6 | public function setSubject($cb) |
|
148 | |||
149 | /** |
||
150 | * Returns the result of the subject closure |
||
151 | * @param Exception $e The Exception instance that you want to build the subject around |
||
152 | * @return string The subject string |
||
153 | */ |
||
154 | 27 | public function getSubject(Exception $e) |
|
162 | |||
163 | /** |
||
164 | * Set an array or a closure to be called that will generate the context array for the notification |
||
165 | * @param callable|array $cb A closure or array that will be set for the context |
||
166 | * @return $this |
||
167 | */ |
||
168 | 3 | public function setContext($cb) |
|
173 | |||
174 | /** |
||
175 | * Returns the result of the context closure |
||
176 | * @param Exception $e The Exception instance that you want to build the context around |
||
177 | * @return array The context array |
||
178 | */ |
||
179 | 24 | public function getContext(Exception $e, $context = []) |
|
193 | |||
194 | /** |
||
195 | * Get the log level |
||
196 | * @return string |
||
197 | */ |
||
198 | 3 | public function getLogLevel() |
|
202 | |||
203 | /** |
||
204 | * Set the log level |
||
205 | * @param string $level The log level |
||
206 | * @return \Tylercd100\LERN\LERN |
||
207 | */ |
||
208 | 3 | public function setLogLevel($level) |
|
213 | |||
214 | /** |
||
215 | * Pushes on another Monolog Handler |
||
216 | * @param HandlerInterface $handler The handler instance to add on |
||
217 | * @return Notifier Returns this |
||
218 | */ |
||
219 | 6 | public function pushHandler(HandlerInterface $handler) |
|
224 | |||
225 | /** |
||
226 | * Triggers the Monolog Logger instance to log an error to all handlers |
||
227 | * @param Exception $e The exception to use |
||
228 | * @param array $context Additional information that you would like to pass to Monolog |
||
229 | * @return bool |
||
230 | * @throws NotifierFailedException |
||
231 | */ |
||
232 | 24 | public function send(Exception $e, array $context = []) |
|
259 | } |
||
260 |