1 | <?php |
||
15 | class Notifier extends Component |
||
16 | { |
||
17 | protected $config; |
||
18 | protected $log; |
||
19 | protected $messageCb; |
||
20 | protected $subjectCb; |
||
21 | protected $contextCb; |
||
22 | |||
23 | /** |
||
24 | * @var array |
||
25 | */ |
||
26 | private $absolutelyDontHandle = [ |
||
27 | \Tylercd100\LERN\Exceptions\NotifierFailedException::class, |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * You can provide a Monolog Logger instance to use in the constructor |
||
32 | * @param Logger|null $log Logger instance to use |
||
33 | */ |
||
34 | 75 | public function __construct(Logger $log = null) |
|
43 | |||
44 | /** |
||
45 | * Transforms a value into a closure that returns itself when called |
||
46 | * @param callable|string $cb The value that you want to wrap in a closure |
||
47 | * @return callable |
||
48 | */ |
||
49 | 15 | private function wrapValueInClosure($cb) |
|
57 | |||
58 | /** |
||
59 | * Set a string or a closure to be called that will generate the message body for the notification |
||
60 | * @param callable|string $cb A closure or string that will be set for the message |
||
61 | * @return $this |
||
62 | */ |
||
63 | 6 | public function setMessage($cb) |
|
68 | |||
69 | /** |
||
70 | * Returns the result of the message closure |
||
71 | * @param Exception $e The Exception instance that you want to build the message around |
||
72 | * @return string The message string |
||
73 | */ |
||
74 | 30 | public function getMessage(Exception $e) |
|
88 | |||
89 | /** |
||
90 | * Gets a basic Exception message |
||
91 | * @param Exception $e The Exception instance that you want to build the message around |
||
92 | * @return String Returns the message string |
||
93 | */ |
||
94 | 3 | public function getMessageViaDefault(Exception $e) |
|
102 | |||
103 | /** |
||
104 | * Gets the Exception message using a callback if it is set |
||
105 | * @param Exception $e The Exception instance that you want to build the message around |
||
106 | * @return String|false Returns the message string or false |
||
107 | */ |
||
108 | 9 | public function getMessageViaCallback(Exception $e) |
|
115 | |||
116 | /** |
||
117 | * Gets the Exception message using a Laravel view file |
||
118 | * @param Exception $e The Exception instance that you want to build the message around |
||
119 | * @return String|false Returns the message string or false |
||
120 | */ |
||
121 | 30 | public function getMessageViaView(Exception $e) |
|
135 | |||
136 | /** |
||
137 | * Set a string or a closure to be called that will generate the subject line for the notification |
||
138 | * @param callable|string $cb A closure or string that will be set for the subject line |
||
139 | * @return $this |
||
140 | */ |
||
141 | 6 | public function setSubject($cb) |
|
146 | |||
147 | /** |
||
148 | * Returns the result of the subject closure |
||
149 | * @param Exception $e The Exception instance that you want to build the subject around |
||
150 | * @return string The subject string |
||
151 | */ |
||
152 | 21 | public function getSubject(Exception $e) |
|
160 | |||
161 | /** |
||
162 | * Set an array or a closure to be called that will generate the context array for the notification |
||
163 | * @param callable|array $cb A closure or array that will be set for the context |
||
164 | * @return $this |
||
165 | */ |
||
166 | 3 | public function setContext($cb) |
|
171 | |||
172 | /** |
||
173 | * Returns the result of the context closure |
||
174 | * @param Exception $e The Exception instance that you want to build the context around |
||
175 | * @return array The context array |
||
176 | */ |
||
177 | 18 | public function getContext(Exception $e, $context = []) |
|
191 | |||
192 | /** |
||
193 | * Get the log level |
||
194 | * @return string |
||
195 | */ |
||
196 | 3 | public function getLogLevel() |
|
200 | |||
201 | /** |
||
202 | * Set the log level |
||
203 | * @param string $level The log level |
||
204 | * @return \Tylercd100\LERN\LERN |
||
205 | */ |
||
206 | 3 | public function setLogLevel($level) |
|
211 | |||
212 | /** |
||
213 | * Pushes on another Monolog Handler |
||
214 | * @param HandlerInterface $handler The handler instance to add on |
||
215 | * @return Notifier Returns this |
||
216 | */ |
||
217 | 6 | public function pushHandler(HandlerInterface $handler) |
|
222 | |||
223 | /** |
||
224 | * Triggers the Monolog Logger instance to log an error to all handlers |
||
225 | * @param Exception $e The exception to use |
||
226 | * @param array $context Additional information that you would like to pass to Monolog |
||
227 | * @return bool |
||
228 | * @throws NotifierFailedException |
||
229 | */ |
||
230 | 15 | public function send(Exception $e, array $context = []) |
|
255 | } |
||
256 |