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