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 | * You can provide a Monolog Logger instance to use in the constructor |
||
25 | * @param Logger|null $log Logger instance to use |
||
26 | */ |
||
27 | 69 | public function __construct(Logger $log = null) |
|
36 | |||
37 | /** |
||
38 | * Transforms a value into a closure that returns itself when called |
||
39 | * @param callable|string $cb The value that you want to wrap in a closure |
||
40 | * @return callable |
||
41 | */ |
||
42 | 15 | private function wrapValueInClosure($cb) |
|
50 | |||
51 | /** |
||
52 | * Set a string or a closure to be called that will generate the message body for the notification |
||
53 | * @param callable|string $cb A closure or string that will be set for the message |
||
54 | * @return $this |
||
55 | */ |
||
56 | 6 | public function setMessage($cb) |
|
61 | |||
62 | /** |
||
63 | * Returns the result of the message closure |
||
64 | * @param Exception $e The Exception instance that you want to build the message around |
||
65 | * @return string The message string |
||
66 | */ |
||
67 | 27 | public function getMessage(Exception $e) |
|
81 | |||
82 | /** |
||
83 | * Gets a basic Exception message |
||
84 | * @param Exception $e The Exception instance that you want to build the message around |
||
85 | * @return String Returns the message string |
||
86 | */ |
||
87 | 3 | public function getMessageViaDefault(Exception $e) |
|
95 | |||
96 | /** |
||
97 | * Gets the Exception message using a callback if it is set |
||
98 | * @param Exception $e The Exception instance that you want to build the message around |
||
99 | * @return String|false Returns the message string or false |
||
100 | */ |
||
101 | 9 | public function getMessageViaCallback(Exception $e) |
|
108 | |||
109 | /** |
||
110 | * Gets the Exception message using a Laravel view file |
||
111 | * @param Exception $e The Exception instance that you want to build the message around |
||
112 | * @return String|false Returns the message string or false |
||
113 | */ |
||
114 | 27 | public function getMessageViaView(Exception $e) |
|
128 | |||
129 | /** |
||
130 | * Set a string or a closure to be called that will generate the subject line for the notification |
||
131 | * @param callable|string $cb A closure or string that will be set for the subject line |
||
132 | * @return $this |
||
133 | */ |
||
134 | 6 | public function setSubject($cb) |
|
139 | |||
140 | /** |
||
141 | * Returns the result of the subject closure |
||
142 | * @param Exception $e The Exception instance that you want to build the subject around |
||
143 | * @return string The subject string |
||
144 | */ |
||
145 | 18 | public function getSubject(Exception $e) |
|
153 | |||
154 | /** |
||
155 | * Set an array or a closure to be called that will generate the context array for the notification |
||
156 | * @param callable|array $cb A closure or array that will be set for the context |
||
157 | * @return $this |
||
158 | */ |
||
159 | 3 | public function setContext($cb) |
|
164 | |||
165 | /** |
||
166 | * Returns the result of the context closure |
||
167 | * @param Exception $e The Exception instance that you want to build the context around |
||
168 | * @return array The context array |
||
169 | */ |
||
170 | 15 | public function getContext(Exception $e, $context = []) |
|
184 | |||
185 | /** |
||
186 | * Pushes on another Monolog Handler |
||
187 | * @param HandlerInterface $handler The handler instance to add on |
||
188 | * @return Notifier Returns this |
||
189 | */ |
||
190 | 6 | public function pushHandler(HandlerInterface $handler) { |
|
194 | |||
195 | /** |
||
196 | * Triggers the Monolog Logger instance to log an error to all handlers |
||
197 | * @param Exception $e The exception to use |
||
198 | * @param array $context Additional information that you would like to pass to Monolog |
||
199 | * @return bool |
||
200 | * @throws NotifierFailedException |
||
201 | */ |
||
202 | 15 | public function send(Exception $e, array $context = []) |
|
227 | } |
||
228 |