| Total Complexity | 10 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class Mail extends AbstractDriver |
||
| 9 | { |
||
| 10 | |||
| 11 | protected function prepare() |
||
| 12 | { |
||
| 13 | $this->config['from_name'] = $this->config['from_name'] ?: 'Log Envelope'; |
||
| 14 | $this->config['from_email'] = $this->config['from_email'] ?: 'logenvelope@'. $this->data['host']; |
||
| 15 | } // end prepare |
||
| 16 | |||
| 17 | protected function check() |
||
| 18 | { |
||
| 19 | return $this->isEnabled() && (isset($this->config['to']) && $this->config['to']); |
||
| 20 | } // end check |
||
| 21 | |||
| 22 | public function send() |
||
| 23 | { |
||
| 24 | if (!$this->check()) { |
||
| 25 | return; |
||
| 26 | } |
||
| 27 | |||
| 28 | $data = $this->data; |
||
| 29 | $config = $this->config; |
||
| 30 | |||
| 31 | if ($this->isMailablePossible()) { |
||
| 32 | MailFacade::queue(new LogEmail($data, $config)); |
||
| 33 | return; |
||
| 34 | } |
||
| 35 | |||
| 36 | MailFacade::queue('log-envelope::main', $data, function($message) use ($data, $config) { |
||
| 37 | $subject = sprintf('[%s] @ %s: %s', $data['class'], $data['host'], $data['exception']); |
||
| 38 | |||
| 39 | // to protect from gmail's anchors automatic generation |
||
| 40 | $message->setBody( |
||
| 41 | preg_replace( |
||
| 42 | ['~\.~', '~http~'], |
||
| 43 | ['<span>.</span>', '<span>http</span>'], |
||
| 44 | $message->getBody() |
||
| 45 | ) |
||
| 46 | ); |
||
| 47 | |||
| 48 | $message->to($config['to']) |
||
| 49 | ->from($config['from_email'], $config['from_name']) |
||
| 50 | ->subject($subject); |
||
| 51 | }); |
||
| 52 | } // end send |
||
| 53 | |||
| 54 | private function isMailablePossible() |
||
| 57 | } // end isMailablePossible |
||
| 58 | |||
| 59 | } |
||
| 60 |