1 | <?php |
||
11 | class Notifier extends Component { |
||
12 | protected $config; |
||
13 | protected $log; |
||
14 | protected $messageCb; |
||
15 | protected $subjectCb; |
||
16 | protected $contextCb; |
||
17 | |||
18 | /** |
||
19 | * You can provide a Monolog Logger instance to use in the constructor |
||
20 | * @param Logger|null $log Logger instance to use |
||
21 | */ |
||
22 | 57 | public function __construct(Logger $log = null) { |
|
23 | 57 | if ($log === null) { |
|
24 | 57 | $log = new Logger(config('lern.notify.channel')); |
|
25 | 57 | } |
|
26 | |||
27 | 57 | $this->config = config('lern.notify'); |
|
28 | 57 | $this->log = $log; |
|
29 | 57 | } |
|
30 | |||
31 | /** |
||
32 | * Transforms a value into a closure that returns itself when called |
||
33 | * @param callable|string $cb The value that you want to wrap in a closure |
||
34 | * @return callable |
||
35 | */ |
||
36 | 15 | private function wrapValueInClosure($cb) { |
|
43 | |||
44 | /** |
||
45 | * Set a string or a closure to be called that will generate the message body for the notification |
||
46 | * @param callable|string $cb A closure or string that will be set for the message |
||
47 | * @return $this |
||
48 | 6 | */ |
|
49 | public function setMessage($cb) |
||
54 | |||
55 | /** |
||
56 | * Returns the result of the message closure |
||
57 | * @param Exception $e The Exception instance that you want to build the message around |
||
58 | * @return string The message string |
||
59 | 15 | */ |
|
60 | 15 | public function getMessage(Exception $e) { |
|
71 | |||
72 | /** |
||
73 | * Set a string or a closure to be called that will generate the subject line for the notification |
||
74 | * @param callable|string $cb A closure or string that will be set for the subject line |
||
75 | 6 | * @return $this |
|
76 | */ |
||
77 | 6 | public function setSubject($cb) |
|
82 | |||
83 | /** |
||
84 | * Returns the result of the subject closure |
||
85 | * @param Exception $e The Exception instance that you want to build the subject around |
||
86 | 15 | * @return string The subject string |
|
87 | 15 | */ |
|
88 | 6 | public function getSubject(Exception $e) { |
|
95 | |||
96 | /** |
||
97 | * Set an array or a closure to be called that will generate the context array for the notification |
||
98 | 3 | * @param callable|array $cb A closure or array that will be set for the context |
|
99 | * @return $this |
||
100 | 3 | */ |
|
101 | 3 | public function setContext($cb) |
|
106 | |||
107 | /** |
||
108 | * Returns the result of the context closure |
||
109 | 12 | * @param Exception $e The Exception instance that you want to build the context around |
|
110 | * @return array The context array |
||
111 | */ |
||
112 | 12 | public function getContext(Exception $e, $context = []) { |
|
126 | |||
127 | /** |
||
128 | * Pushes on another Monolog Handler |
||
129 | 6 | * @param HandlerInterface $handler The handler instance to add on |
|
130 | 6 | * @return Notifier Returns this |
|
131 | 6 | */ |
|
132 | public function pushHandler(HandlerInterface $handler) { |
||
136 | |||
137 | /** |
||
138 | * Triggers the Monolog Logger instance to log an error to all handlers |
||
139 | * @param Exception $e The exception to use |
||
140 | 12 | * @param array $context Additional information that you would like to pass to Monolog |
|
141 | * @return bool |
||
142 | 12 | * @throws NotifierFailedException |
|
143 | 3 | */ |
|
144 | public function send(Exception $e, array $context = []) { |
||
169 | } |